2015-01-29 5 views
1

Я пытаюсь добавить EditText и кнопку в той же строке, и я хотел бы дать 80% строки editText и 20% к Button.Android LinearLayout RelativeLayout Вес

Вот мой код:

<?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> 

и он не работает ...

Спасибо за любую помощь

ответ

1

Используйте LinearLayout для весов. Вы можете использовать weightSum 10 и дать одной точки зрения веса 8, а другой вес 2.

для Вашего случая:

<ScrollView...> 
    <LinearLayout vertical> 
     <LinearLayout horizontal weightSum=10> 
      <EditText weight=8 /> 
      <Button weight=2 /> 
     </LinearLayout> 
     <Fragment /> 
    </LinearLayout> 
</ScrollView> 
+0

Также важно, чтобы все ваши мнения ребенка имеет высоту из '0dp', чтобы действительно иметь раскол 80-20%. – dharms

+0

Да, это правда, в данном случае 'width =" 0dp "', поскольку это горизонтальный макет – darnmason

Смежные вопросы