我有一個表佈局,我顯示從我的數據庫中的值我有7列的表.. 我將行添加到表格佈局編程添加數據是好.. ..通過使用textviews..but在我的第七列中,我需要添加兩個按鈕..我需要在同一列中的兩個按鈕和另一個旁邊....只能顯示一個按鈕..如何顯示兩行按鈕中的一行同列?是否有可能這樣做? 請幫忙!! 謝謝!如何在表格佈局中的一行的同一列添加兩個按鈕?
這裏就是我如何編程方式添加行:
do
{
tr=new TableRow(this);
tr.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT));
firstCol=new TextView(this);
firstCol.setText("0");
firstCol.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
firstCol.setGravity(Gravity.CENTER);
tr.addView(firstCol);
secondCol=new TextView(this);
secondCol.setText(lead.getString(index0));
secondCol.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
secondCol.setGravity(Gravity.CENTER);
tr.addView(secondCol);
thirdCol=new TextView(this);
thirdCol.setText(lead.getString(index1));
thirdCol.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
thirdCol.setGravity(Gravity.CENTER);
tr.addView(thirdCol);
fourthCol=new TextView(this);
fourthCol.setText(lead.getString(index2));
fourthCol.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
fourthCol.setGravity(Gravity.CENTER);
tr.addView(fourthCol);
fifthCol=new TextView(this);
fifthCol.setText(lead.getString(index3));
fifthCol.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
fifthCol.setGravity(Gravity.CENTER);
tr.addView(fifthCol);
sixthCol=new TextView(this);
sixthCol.setText(lead.getString(index4));
sixthCol.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
sixthCol.setGravity(Gravity.CENTER);
tr.addView(sixthCol);
seventhCol=new Button(this);
seventhCol.setBackground(getApplicationContext().getResources().getDrawable(R.drawable.circ));
tr.addView(seventhCol);
lead_table.addView(tr);
tr.setOnClickListener(this);
}while(lead.moveToNext());
這裏是表格的佈局:
<TableLayout
android:id="@+id/lead_table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="50dp"
android:gravity="center"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/bgbtn"
android:paddingLeft="30dp"
android:text="Lead ID"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bgbtn"
android:paddingLeft="15dp"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bgbtn"
android:paddingLeft="20dp"
android:text="Mobile"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bgbtn"
android:paddingLeft="15dp"
android:text="Product"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bgbtn"
android:paddingLeft="15dp"
android:text="Value"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bgbtn"
android:paddingLeft="15dp"
android:text="Status"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bgbtn"
android:paddingLeft="15dp"
android:text="Action"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
</TableLayout>
從邏輯上思考,如果要讓它們並排顯示,怎樣才能在同一列中顯示2個按鈕?它沒有任何邏輯意義。你可以如何將兩個按鈕放在同一行的兩個不同列中,並將它們顯示爲並排實體。 –
@TheDarkKnight,但我有一個標題的那一欄,這兩個按鈕需要在該專欄下! – shivani
好的,所以你需要做的是在該列中添加兩列,然後將按鈕添加到這些列。讓我嘗試一下。我會盡快回復您 。或者你也可以按照Torben的解決方案,這也將工作,我假設。 –