2013-08-01 2 views
0

У меня есть следующий код XML (частично для этого примера):Убедитесь, что EditText находится непосредственно под ярлыком с помощью LinearLayout

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:paddingLeft="0dp" 
    android:paddingRight="0dp" > 
    <RadioGroup 
     android:id="@+id/rgVehicle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1.5" > 
     <RadioButton 
      android:id="@+id/rbCar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:checked="true" 
      android:text="Car" /> 
     <RadioButton 
      android:id="@+id/rbTruck" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Truck" /> 
     <RadioButton 
      android:id="@+id/rbCycle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Motorcycle" /> 
    </RadioGroup> 
      <EditText 
     android:id="@+id/etToll" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:inputType="numberDecimal" 
     android:layout_weight=".5" /> 
</LinearLayout> 

Для меньшего экрана, как Galaxy Nexus и Nexus One макет выходит так: enter image description here

Как я могу это исправить, так что EditText находится непосредственно под #6 этикетки не показан ниже (независимо от того, какого размера экрана):

enter image description here

+2

Первое, что приходит на мой взгляд, является использование таблицы макета с двумя строками и двумя столбцами –

+0

Как бы реализовать желаемое результат с этим макетом? – Si8

ответ

1

Там вы идете:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" > 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="5. Vehicle type" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <RadioGroup 
     android:id="@+id/rgVehicle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <RadioButton 
      android:id="@+id/rbCar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:checked="true" 
      android:text="Car" /> 

     <RadioButton 
      android:id="@+id/rbTruck" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Truck" /> 

     <RadioButton 
      android:id="@+id/rbCycle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Motorcycle" /> 
    </RadioGroup> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="6. Total amount" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <EditText 
     android:id="@+id/etToll" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:inputType="numberDecimal" /> 
</LinearLayout> 

</LinearLayout> 
1

использовать что-то вроде этого:

<tablelayout> 
     <tablerow android:layout_weightsum="2"> 
     <textview android:layout_weight="1" android:text="4"> 
     <textview android:layout_weight="1" android:text="6"> 
    </tablerow> 

    <tablerow android:layout_weightsum="2"> 
     <radiogroup android:layout_weight="1"> 
     <!-- add radio buttons here --> 
     </radiogroup> 
     <edittext android:layout_weight="1" > 
    </tablerow> 

</tablelayout> 
+0

Где я могу определить, сколько места занимает экран? Я просто сделал пример, и он работает неправильно. – Si8

+1

Что занимает место? я не понимаю твоего вопроса. –

+0

Я думаю, что это может сработать, как я могу получить каждый col до 50%? – Si8

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