1

필드 이름과 필드 값이라는 두 개의 열이있는 양식의 표 레이아웃이 있습니다. 경우에 따라 필드 값이 체크리스트입니다. "checklist"행의 행 높이를 확장하여 listview의 모든 항목을 볼 수있게하고 싶습니다.android tablelayout은 행의 높이를 목록보기 내용으로 확장합니다.

다음 코드는 작은 세로로 스크롤 할 수있는보기의 목록보기를 보여줍니다. 첫 번째 열의 필드 이름과 동일한 높이입니다. 전체 목록을 볼 수 있도록 행 높이를 어떻게 확장합니까? (테이블 셀의 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> 
관련 문제