Android 视图翻转器弄乱了我的布局=(
我使用普通的线条布局来创建我的设计 我的设计非常简单…只是一个显示图片的图像按钮网格。为了给它们一个漂亮的外观,我使用了一个roundcorners.xml文件。如下所示:Android 视图翻转器弄乱了我的布局=(,android,viewflipper,Android,Viewflipper,我使用普通的线条布局来创建我的设计 我的设计非常简单…只是一个显示图片的图像按钮网格。为了给它们一个漂亮的外观,我使用了一个roundcorners.xml文件。如下所示: <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:col
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFFFF"/>
<corners android:radius="10dip"/>
<stroke android:width="8dip"/>
<size android:height="8dip"/>
</shape>
好的…图像按钮过去在2X4网格中显示得很好,所有按钮周围都有一个漂亮的黑色圆角
现在我使用的是ViewFlipper,而不是上面的代码,我使用的是:
viewFlip.addView(myLinearLayoutFullOfImageButtons);
它可以工作,因为我在运行时需要很多屏幕
图像按钮显示出来了,Buuuuuttt…圆角不见了!它们就是不出现!现在我只有平面无聊的图像按钮
下面是完整的代码:
viewFlip = (ViewFlipper) findViewById(R.id.flipper);
//creates a linearlayout
//this linearlayout will contain "lines", those lines will be new linear layouts
LinearLayout lgeral = new LinearLayout (this);
lgeral.setOrientation(LinearLayout.VERTICAL);
lgeral.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1f));
int qtyOfLines = 2;
int qtyOfColumns = 4;
int controle = 0;
//creates "n" linearlayouts, according to the number of lines
for (int j = 0; j < qtyOfLines; j++) {
//creates one "line", a linearlayout
//this will be horizontal, since imagebuttons will be placed, side by side
//like a grid of 2 lines and 4 columns
LinearLayout l1 = new LinearLayout (this);
l1.setOrientation(LinearLayout.HORIZONTAL);
l1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1f));
//this framelayout will contain the imagebutton and textview
FrameLayout fl;
//the loop below is to create "n" imagebuttons according to the number of columns
for (int i = 0; i < (cursorLinhas.getCount()); i++) {
if(controle==cursorLinhas.getCount()){
break;
}
//creates a FrameLayout from layout xml
fl = (FrameLayout)LayoutInflater.from(getBaseContext()).inflate(R.layout.framelayoutstyle, l1, false);
//creates a TextView who will contain the text of imagebutton
TextView textoEscrito;
textoEscrito = (TextView)LayoutInflater.from(getBaseContext()).inflate(R.layout.textviewstyle, fl, false);
//creates a imagebutton from layout xml
ImageButton btn;
btn = (ImageButton)LayoutInflater.from(getBaseContext()).inflate(R.layout.imagebuttonstyle, fl, false);
//sets OnClick for imagebuttons
btn.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick (View v){
//do whatever
}
});
//adds the imagebutton and textview to the FrameLayout
fl.addView(btn);
fl.addView(textoEscrito);
//adds FrameLayout to LinearLayout
l1.addView(fl);
controle++;
if (i == (qtyOfColumns -1)){
cursorLinhas.moveToNext();
break;
}
cursorLinhas.moveToNext();
}
//adds the "line" LinearLayout to the general LinearLayout
lgeral.addView(l1);
}
//adds the general LinearLayout to the ViewFlipper.
//I am using this NOW, and it doesn't show the roundcorners!!!
viewFlip.addView(lgeral);
BEFORE I WAS USING THIS:
//setContentView(lgeral);
viewFlip=(ViewFlipper)findViewById(R.id.flipper);
//创建线性布局
//此线性布局将包含“线”,这些线将是新的线性布局
LinearLayout lgeral=新的LinearLayout(本);
l一般设置方向(线性布局、垂直);
lgeral.setLayoutParams(新的LinearLayout.LayoutParams(LayoutParams.FILL\u父级,LayoutParams.FILL\u父级,1f));
int qtyOfLines=2;
int qtyOfColumns=4;
int controle=0;
//根据行数创建“n”个线性布局
对于(int j=0;j
以前roundcorners.xml位于/layouts文件夹中。现在我将其移动到/drawable,没有任何更改
有什么想法吗
任何帮助都将不胜感激
谢谢!您能添加生成MyLinearlayoutUllofImageButtons的xml布局或代码或任何其他相关代码吗?这不太好用。将代码放在创建按钮的位置,然后放入线性布局中。大家好……我刚刚添加了全部代码……有什么帮助吗?谢谢!
viewFlip = (ViewFlipper) findViewById(R.id.flipper);
//creates a linearlayout
//this linearlayout will contain "lines", those lines will be new linear layouts
LinearLayout lgeral = new LinearLayout (this);
lgeral.setOrientation(LinearLayout.VERTICAL);
lgeral.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1f));
int qtyOfLines = 2;
int qtyOfColumns = 4;
int controle = 0;
//creates "n" linearlayouts, according to the number of lines
for (int j = 0; j < qtyOfLines; j++) {
//creates one "line", a linearlayout
//this will be horizontal, since imagebuttons will be placed, side by side
//like a grid of 2 lines and 4 columns
LinearLayout l1 = new LinearLayout (this);
l1.setOrientation(LinearLayout.HORIZONTAL);
l1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1f));
//this framelayout will contain the imagebutton and textview
FrameLayout fl;
//the loop below is to create "n" imagebuttons according to the number of columns
for (int i = 0; i < (cursorLinhas.getCount()); i++) {
if(controle==cursorLinhas.getCount()){
break;
}
//creates a FrameLayout from layout xml
fl = (FrameLayout)LayoutInflater.from(getBaseContext()).inflate(R.layout.framelayoutstyle, l1, false);
//creates a TextView who will contain the text of imagebutton
TextView textoEscrito;
textoEscrito = (TextView)LayoutInflater.from(getBaseContext()).inflate(R.layout.textviewstyle, fl, false);
//creates a imagebutton from layout xml
ImageButton btn;
btn = (ImageButton)LayoutInflater.from(getBaseContext()).inflate(R.layout.imagebuttonstyle, fl, false);
//sets OnClick for imagebuttons
btn.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick (View v){
//do whatever
}
});
//adds the imagebutton and textview to the FrameLayout
fl.addView(btn);
fl.addView(textoEscrito);
//adds FrameLayout to LinearLayout
l1.addView(fl);
controle++;
if (i == (qtyOfColumns -1)){
cursorLinhas.moveToNext();
break;
}
cursorLinhas.moveToNext();
}
//adds the "line" LinearLayout to the general LinearLayout
lgeral.addView(l1);
}
//adds the general LinearLayout to the ViewFlipper.
//I am using this NOW, and it doesn't show the roundcorners!!!
viewFlip.addView(lgeral);
BEFORE I WAS USING THIS:
//setContentView(lgeral);