Android LinearLayout相对重量
我试图在同一行上添加一个EditText和一个按钮,我想给EditText 80%的行和按钮20%的行 这是我的密码:Android LinearLayout相对重量,android,layout,Android,Layout,我试图在同一行上添加一个EditText和一个按钮,我想给EditText 80%的行和按钮20%的行 这是我的密码: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollViewChoosePlace"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="1" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<EditText
android:id="@+id/et_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:hint="location"
android:inputType="text" />
<!-- android:layout_alignParentTop="true" -->
<Button
android:id="@+id/btn_find"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toEndOf="@id/et_location"
android:layout_toRightOf="@id/et_location"
android:layout_weight="0.2"
android:text="find" />
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/btn_find" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
但它不起作用
感谢您的帮助使用
线性布局
进行称重。您可以使用10的weightSum
,一个视图的权重为8,另一个视图的权重为2
对于您的情况:
<ScrollView...>
<LinearLayout vertical>
<LinearLayout horizontal weightSum=10>
<EditText weight=8 />
<Button weight=2 />
</LinearLayout>
<Fragment />
</LinearLayout>
</ScrollView>
同样重要的是,让所有子视图的高度都为0dp
,这样才能真正实现80-20%的分割。是的,在这种情况下width=“0dp”
是水平布局