Reputation: 35
I'm trying to add an EditText and a Button on the same line and i would like to give 80% of the line to the editText and 20% to the Button.
Here is my code:
<?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>
and it doesn't work...
Thanks for any help
Upvotes: 1
Views: 470
Reputation: 2732
Use a LinearLayout
for weights. You can use a weightSum
of 10 and give one view a weight of 8 and the other a weight of 2.
For your case:
<ScrollView...>
<LinearLayout vertical>
<LinearLayout horizontal weightSum=10>
<EditText weight=8 />
<Button weight=2 />
</LinearLayout>
<Fragment />
</LinearLayout>
</ScrollView>
Upvotes: 1