我正在设计我的应用程序UI。我需要一个像这样的布局:
(<和>是按钮)。问题是,我不知道如何确保TextView会填满剩余的空间,因为有两个按钮的大小是固定的。
如果我使用fill_parent显示文本视图,第二个按钮(>)不能显示。
我如何制作一个看起来像图像的布局?
发布于 2014-09-11 15:04:51
woodshy的答案对我很有效,而且它比Ungureanu Liviu的答案更简单,因为它没有使用RelativeLayout
。为了清楚起见,我给出了我的布局:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:layout_width = "80dp"
android:layout_weight = "0"
android:layout_height = "wrap_content"
android:text="<"/>
<TextView
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:layout_weight = "1"/>
<Button
android:layout_width = "80dp"
android:layout_weight = "0"
android:layout_height = "wrap_content"
android:text=">"/>
</LinearLayout>
发布于 2011-06-11 22:56:36
如果<TextView>
放在LinearLayout
中,请将TextView
的<
和>
的Layout_weight
属性分别设置为0和1。
如果您正在使用RelativeLayout
,请将<
和>
左右对齐,并将TextView
的"Layout to left of“和"Layout to right of”属性设置为<
和>
的ids。
发布于 2011-06-11 23:01:51
如果你使用RelativeLayout
,你可以这样做:
<RelativeLayout
android:layout_width = "fill_parent"
android:layout_height = "fill_parent">
<ImageView
android:id = "@+id/my_image"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentTop ="true" />
<RelativeLayout
android:id="@+id/layout_bottom"
android:layout_width="fill_parent"
android:layout_height = "50dp"
android:layout_alignParentBottom = "true">
<Button
android:id = "@+id/but_left"
android:layout_width = "80dp"
android:layout_height = "wrap_content"
android:text="<"
android:layout_alignParentLeft = "true"/>
<TextView
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:layout_toLeftOf = "@+id/but_right"
android:layout_toRightOf = "@id/but_left" />
<Button
android:id = "@id/but_right"
android:layout_width = "80dp"
android:layout_height = "wrap_content"
android:text=">"
android:layout_alignParentRight = "true"/>
</RelativeLayout>
</RelativeLayout>
https://stackoverflow.com/questions/6316540
复制相似问题