ViewFlipper перепутался с моими раскладками = ( - PullRequest
1 голос
/ 09 ноября 2011

Я использовал простые 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 был в папке / layout.Теперь я переместил его в / drawable и ничего не изменилось.

Любые идеи?

Любая помощь будет оценена.

Спасибо!

...