我需要用两个窗体小部件(例如 - 两个按钮)创建一个简单的布局。第一个必须填写父级布局的所有可用宽度,第二个必须具有一定的大小。Android:如何创建这个简单的布局?
这就是我需要:
如果我设置FILL_PARENT到第一小 - 我没有看到第二个。它只是从布局的视图区域吹走:)我不知道如何解决这个问题...
我需要用两个窗体小部件(例如 - 两个按钮)创建一个简单的布局。第一个必须填写父级布局的所有可用宽度,第二个必须具有一定的大小。Android:如何创建这个简单的布局?
这就是我需要:
如果我设置FILL_PARENT到第一小 - 我没有看到第二个。它只是从布局的视图区域吹走:)我不知道如何解决这个问题...
要做到这一点,最简单的方法是使用layout_weight
与LinearLayout
。注意第一个TextView的宽度是"0dp"
,这意味着“忽略我并使用重量”。重量可以是任何数字;因为它是唯一的加权视图,它将扩展以填充可用空间。
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<TextView
android:layout_width="25dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
你可以用RelativeLayout或FrameLayout来完成。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:background="#ccccee"
android:text="A label. I need to fill all available width." />
<TextView
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:paddingRight="5dp"
android:background="#aaddee"
android:text=">>" />
</RelativeLayout>
谢谢!这正是我需要的! – JavaRunner