ViewFlipper搞砸了我的布局=(

时间:2011-11-09 02:22:16

标签: android viewflipper

我使用普通的LinerLayouts来创建我的设计。

我的设计很简单......只是一个ImageButtons网格显示他们的照片。为了给他们一个好看,我使用的是roundcorners.xml文件。像这样:

    <?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>

我曾经创建过我的整个屏幕,然后将其设置为这样的视图:

    setContentView(myLinearLayoutFullOfImageButtons);

好的... ImageButtons曾经很好地出现在2X4网格中,周围有一个漂亮的圆角黑角。

现在我正在使用ViewFlipper而不是上面的代码,我正在使用它:

    viewFlip.addView(myLinearLayoutFullOfImageButtons);

它有效,因为我在运行时需要很多屏幕。

显示了ImageButtons,BUUUUUTTTT ......缺少圆角!他们只是没有出现!现在我只有平坦无聊的图像按钮。

下面是完整的代码:

        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);        

在roundcorners.xml处于文件夹/布局之前。现在我将它移动到/ drawable并且没有任何改变。

有什么想法吗?

任何帮助将不胜感激。

谢谢!

0 个答案:

没有答案
相关问题