0

私のアプリケーションでは、以下の画像のようにレイアウトを作成したいと考えています:

ここに画像の説明を入力

では、それを可能にする方法は?

私は以下のコードのようなことをしました:

public void showResult()
{

    List<TextView> textListWord = new ArrayList<TextView>(tempEmployerList.size());
    List<TextView> textListAnswer = new ArrayList<TextView>(tempEmployerList.size());
    List<TextView> imageListAnswer = new ArrayList<TextView>(tempEmployerList.size());
    for(int i = 0; i<=tempEmployerList.size()-1; i++)
    {    
        LinearLayout innerLayout = new LinearLayout(this);
        innerLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        innerLayout.setBackgroundColor(0x00000000);

        // set the Multiple TextView
        TextView mHeading = new TextView(getApplicationContext());
        TextView middleValue = new TextView(getApplicationContext());
        TextView aImageView = new TextView(getApplicationContext());

        mHeading.setText("\n"+"1");
        //mHeading.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        mHeading.setTextColor(0xFFFF0000);
        mHeading.setPadding(3, 0, 0, 0);


        middleValue.setText("\n"+"2");
        //middleValue.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        middleValue.setTextColor(0xFFFF0000);
        middleValue.setGravity(Gravity.RIGHT);
        middleValue.setPadding(2, 0, 9, 0);

        aImageView.setText("\n"+"3");
        //aImageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        aImageView.setGravity(Gravity.RIGHT);
        aImageView.setTextColor(0xFF000000);
        aImageView.setPadding(0, 0, 9, 0);

        View line = new View(getApplicationContext());
        //line.setOrientation(1);
        line.setLayoutParams(new LayoutParams(2, android.view.ViewGroup.LayoutParams.FILL_PARENT)); 
        line.setBackgroundColor(0xFF000000); 

        /**** Any other text view setup code ****/    

        innerLayout.addView(mHeading);
        innerLayout.addView(middleValue);
        innerLayout.addView(aImageView);
        innerLayout.addView(line);
        myLinearLayout.addView(innerLayout);  

        textListWord.add(mHeading); 
        textListAnswer.add(middleValue);
        imageListAnswer.add(aImageView);

    } 
}

そのようなビューを作成するには、さらに何をしなければならないか教えてください。ありがとう。

4

1 に答える 1

1

LinearLayout の代わりに TableLayout と TableRow を試してください。

xml で TableLayout を作成することもできますが、それは静的で TableRows を追加すると思います。Java で TableLayout を作成するには、

TableLayout tblLayout=new TableLayout(this); 

LayoutParams を設定しているように、Java で LayoutParams とテーブル レイアウトのその他のプロパティを設定します。

LayoutParams params=new LayoutParams(LayoutParams.Fill_Parent, LayoutParams.Wrap_Content); 
tblLayout.setLayoutParams(params);

TableRows の作成と挿入のループを作成します。

for(int i=0;i<arrList1.size();i++)
{
   TableRow row=new TableRow(this);
   row.setLayoutParams(params);

   TextView lbl1=new TextView(this);
   lbl1.setText(arrList1.get(i));
   row.addView(lbl1);

   TextView lbl2=new TextView(this);
   lbl2.setText(arrList2.get(i));
   row.addView(lbl2);

   TextView lbl3=new TextView(this);
   lbl3.setText(arrList3.get(i));
   row.addView(lbl3);

   tblLayout.addView(row);
}
于 2012-01-10T04:47:07.790 に答える