我需要创建一个适合数据行的dinamic表。我想要的行将有一个特定的形式,如下所示:
所以,为了得到它,我使用了relativeLayouts。问题是我首先尝试使用.xml来查看哪些参数将包含它形成的不同视图,我得到它,但现在我无法在代码中复制它。
这是我的代码:
TableLayout linkRoutesTable = (TableLayout) findViewById(R.id.layoutLinkRoutes);
//ROW:
TableRow linkRouteRow = new TableRow(this);
linkRouteRow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
linkRouteRow.setId(i)
//RELATIVELAYOUT:
float px0 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics());
RelativeLayout relativeLayout = new RelativeLayout(this);
relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(0, (int)px0)));
//CONTENT:
// BUTTON: ...
// NUMBER:...
// ADDRESS:...
// NAME: ...
relativeLayout.addView(number);
relativeLayout.addView(name);
relativeLayout.addView(address);
relativeLayout.addView(button);
linkRouteRow.addView(relativeLayout);
linkRouteTable.addView(linkRouteRow);
linkRoutesTable.refreshDrawableState();
它没有显示任何内容......
.xml显示确定,这是:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" android:orientation="vertical">
<TableRow>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_weight="1"
android:id="@+id/layoutLinkRoutes" >
<Button android:text="Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button1" android:layout_alignParentTop="true" android:layout_alignParentRight="true"></Button>
<TextView android:textStyle="bold" android:textSize="45dp" android:text="1" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_marginLeft="22dp"></TextView>
<TextView android:text="TextView" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/button1" android:layout_toRightOf="@+id/textView1" android:layout_marginLeft="16dp"></TextView>
<TextView android:text="TextView" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_alignParentTop="true" android:layout_alignLeft="@+id/textView3"></TextView>
</RelativeLayout>
</TableRow>
我在代码中做错了什么?我需要一些帮助,我尝试了一切。
如果我不使用relativeLayouts和行,它会显示一些但不好的...所以问题是行和relativelayout
非常感谢...
答案 0 :(得分:1)