Android:具有行跨度的布局 [英] Android: Layout with row span
问题描述
我试图弄清楚如何创建一个看起来像这样的布局.
I am trying to figure out how to create a layout that looks like this.
--------------------------------
Sep Text here
--------------------------------
text 1 here | IMG
text 2 Here |
--------------------------------
我尝试使用表布局内部的表布局来执行此操作,但比起我无法访问文本1"和文本2"来设置它们的值有关我应该如何实现这一点的任何想法?您可以告诉我如何访问位于两个布局以下的元素.
I have tried to do this with a table layout inside of a table layout but than I am having trouble accessing the "text 1" and text 2" to set their values. Any thoughts on how I should accomplish this? Or maybe you can tell me how to access elements that are down two levels of layouts.
推荐答案
使用RelativeLayout可以轻松完成此操作.它将按照以下方式实现:
This can be easily accomplished with a RelativeLayout. It would be implemented in the lines of the following:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/img"
android:src="@drawable/my_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:layout_alignParentRight="true" />
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:layout_alignParentLeft="true" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text1"
android:layout_alignParentLeft="true" />
</RelativeLayout>
通过代码访问text1和text2可以通过以下方式完成:
Accessing text1 and text2 by code could be done by:
TextView text1 = (TextView) findViewById(R.id.text1);
TextView text2 = (TextView) findViewById(R.id.text2);
// set text
text1.setText("foo");
text2.setText("bar");
希望有帮助!
这篇关于Android:具有行跨度的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!