ViewFlipper messed with my layouts =(

我们两清 提交于 2019-12-08 03:58:29

问题


I was using plain LinerLayouts to create my design.

My design was pretty simple... just a grid of ImageButtons showing their pictures. To give a nice look to them I was using a roundcorners.xml file. Like this:

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

I used to create my whole screen and then set it as a view like this:

    setContentView(myLinearLayoutFullOfImageButtons);

Ok... ImageButtons used to appear nicely in a 2X4 grid with a nice rounded black corner around all of them.

Now I am using ViewFlipper and instead of the above code, I am using this:

    viewFlip.addView(myLinearLayoutFullOfImageButtons);

It works, since I need many screens in runtime.

ImageButtons are shown, BUUUUUTTTT... the round corners are missing! They JUST don't appear! Now I have just the flat boring imagebuttons.

BELOW it's the full code:

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

Before the roundcorners.xml was in the folder /layouts. Now I moved it to /drawable and nothing changed.

Any ideas?

Any help will be appreciated.

Thanks!

来源:https://stackoverflow.com/questions/8059670/viewflipper-messed-with-my-layouts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!