[英]Android LinearLayout RelativeLayout Weight
我试图在同一行上添加一个EditText和一个Button,我想将80%的行提供给editText,将20%的行提供给Button。
这是我的代码:
<?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>
而且不起作用...
谢谢你的帮助
将LinearLayout
用于权重。 您可以使用weightSum
为10,并给一个视图赋予8的权重,给另一个视图赋予2的权重。
对于您的情况:
<ScrollView...>
<LinearLayout vertical>
<LinearLayout horizontal weightSum=10>
<EditText weight=8 />
<Button weight=2 />
</LinearLayout>
<Fragment />
</LinearLayout>
</ScrollView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.