如何使用View进行布局填充剩余空间?
我正在设计我的应用程序UI。 我需要一个如下所示的布局:
(<和>是按钮)。 问题是,我不知道如何确保TextView将填充剩余的空间,其中两个按钮的大小是固定的。
如果我为文本视图使用fill_parent,则不能显示第二个按钮(>)。
我如何制作一个看起来像图像的布局?
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>
如果<TEXT VIEW>放置在LinearLayout中,则为TextView设置<和>的Layout_weight属性为0和1。
如果RelativeLayout将<左右对齐<左右对齐>并将“布局左侧”和“右侧布局”属性设置为<和>的ID,
如果你使用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>
链接地址: http://www.djcxy.com/p/93261.html