1

我有一個窗體的表格佈局有兩列 - 一個字段名稱和一個字段值。在某些情況下,字段值是一個清單。我希望「清單」行的行高擴大,以便我可以在列表視圖中看到所有項目。android tablelayout展開行高到列表視圖的內容

以下代碼顯示了一個小垂直可滾動視圖中的listview,其高度與第一列中的字段名稱相同。如何擴大行高以便我可以看到整個列表? (表格單元格中的FrameLayout可以覆蓋圖標或文字)。

// get the table 
TableLayout table = FindViewById<TableLayout>(Resource.Id.formTable); 

// make a new table row 
TableRow row = new TableRow(this); 

// add the field name (left column) 
TextView rowName = new TextView(this); 
rowName.Text = field.Name + ":"; 
rowName.Gravity = GravityFlags.Right | GravityFlags.CenterVertical; 
TableRow.LayoutParams tableLayoutParams = new TableRow.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.FillParent); 
tableLayoutParams.Gravity = GravityFlags.Right | GravityFlags.CenterVertical; 
tableLayoutParams.Weight = 1.0f; 
tableLayoutParams.Width = 0; 
row.AddView(rowName, tableLayoutParams); 

// add the field value (right column - in this case, a listview for a checklist) 
FrameLayout frameLayout = new FrameLayout(this); 

List<string> strings = field.Items.ToList(); 
ListView listView = new ListView(this); 
listView.Adapter = new ListViewFormAdapterCheckList(this, strings); 

frameLayout.AddView(listView); 
tableLayoutParams = new TableRow.LayoutParams(TableLayout.LayoutParams.WrapContent, TableLayout.LayoutParams.WrapContent); 
tableLayoutParams.SetMargins(0, 10, 0, 0); 
tableLayoutParams.Width = 0; 
row.AddView(frameLayout, tableLayoutParams); 

回答

0

從來沒有這樣的工作與列表視圖。使用的LinearLayout,而不是...

// get the table 
TableLayout table = FindViewById<TableLayout>(Resource.Id.formTable); 

// make a new table row 
TableRow row = new TableRow(this); 

// put the field name at the top of the row 
rowName.Gravity = GravityFlags.Right | GravityFlags.Top; 
rowName.SetPadding(0, 20, 20, 0); 

// frame layout so we can overlay an image/icon over the list 
FrameLayout frameLayout = new FrameLayout(this); 
frameLayout.Id = kCurrentFieldId++; 
frameLayout.Tag = index; 
mFieldToView[field] = frameLayout; 

List<string> strings = field.Items.ToList(); 
LinearLayout listLayout = new LinearLayout(this); 
listLayout.Orientation = Android.Widget.Orientation.Vertical; 

LayoutInflater inflater = (LayoutInflater) GetSystemService(Context.LayoutInflaterService); 
foreach (string item in strings) 
{ 
    View v = inflater.Inflate(Resource.Layout.list_checklist, null); 
    v.FindViewById<CheckBox>(Resource.Id.checkbox).Text = item; 
    listLayout.AddView(v); 
} 

frameLayout.AddView(listLayout); 

tableLayoutParams = new TableRow.LayoutParams(TableLayout.LayoutParams.WrapContent, TableLayout.LayoutParams.WrapContent); 
tableLayoutParams.SetMargins(0, 10, 0, 0); 
tableLayoutParams.Width = 0; 
tableLayoutParams.Weight = 2.0f; 
row.AddView(frameLayout, tableLayoutParams); 

list_checklist定義爲:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="5dip"> 
    <CheckBox 
     android:id="@+id/checkbox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:gravity="center_vertical" 
     android:text="checkdesc" /> 
</RelativeLayout>