2015-06-07 2 views
0

Мой сценарий выглядит так: У меня есть линейная компоновка, в которой у меня есть один вид изображения и около 10 editTexts. Я хочу, чтобы ImageView составлял половину размера экрана, а оставшиеся тексты редактирования занимали остальную часть пространства и, если нужно, прокручивали прокрутку.Android layout_weight для переполнения линейной высоты макета

Я завернул свою линейную компоновку в виде прокрутки и назначил сумму веса 10 на линейный макет. Затем назначенный layout_weight из 5 в imageView и остальное все остались с layout_height of wrap_content. Но это полностью скрывает изображение. Как мне получить вид макета, который я хочу?

Мой layout.xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:fillViewport="true" 
     > 
    <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      > 
     <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="10dp" 
       android:id="@+id/imageView" android:layout_gravity="center" android:background="#bcddff" 
       /> 
     <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Launch Camera" 
       android:id="@+id/button" android:layout_gravity="center"/> 
     <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="Enter Name" 
       android:id="@+id/name" android:layout_gravity="center"/> 
     <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="Mobile No." 
       android:id="@+id/mobile" android:layout_gravity="center" android:inputType="phone"/> 
     <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="Whatsapp No." 
       android:id="@+id/whatsapp" android:layout_gravity="center" android:inputType="phone"/> 
     <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="Email" 
       android:id="@+id/email" android:layout_gravity="center"/> 
     <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="Age" 
       android:id="@+id/age" android:layout_gravity="center"/> 
     <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="Address" 
       android:id="@+id/address" android:layout_gravity="center"/> 
     <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="City" 
       android:id="@+id/city" android:layout_gravity="center"/> 
     <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="State" 
       android:id="@+id/state" android:layout_gravity="center"/> 
     <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="Gender(M/F)" 
       android:id="@+id/gender" android:layout_gravity="center"/> 
     <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:hint="Remarks" 
       android:id="@+id/remarks" android:layout_gravity="center"/> 
    </LinearLayout> 
</ScrollView> 
+0

http://stackoverflow.com/questions/17330216/layout-weight-does-not-work-when-the-layout-inside-a-scrollview-is- больше, чем т –

ответ

0

При установке вес макета либо высота должна быть match_parent или 0dp (Если Match_parent макет получить больше, как вес снижается, и по иронии судьбы, если 0dp, то макет увеличивается по мере увеличения веса). Макет макета не работает точно, когда родительский объект находится в wrap_content.

Надеется, что это помогает,

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:fillViewport="true" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

     <ImageView 
      android:id="@+id/imageView" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="#bcddff" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

     <Button 
      android:id="@+id/button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="Launch Camera" /> 

     <EditText 
      android:id="@+id/name" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="Enter Name" > 

      <requestFocus /> 
     </EditText> 

     <EditText 
      android:id="@+id/mobile" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="Mobile No." 
      android:inputType="phone" /> 

     <EditText 
      android:id="@+id/whatsapp" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="Whatsapp No." 
      android:inputType="phone" /> 

     <EditText 
      android:id="@+id/email" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="Email" /> 

     <EditText 
      android:id="@+id/age" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="Age" /> 

     <EditText 
      android:id="@+id/address" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="Address" /> 

     <EditText 
      android:id="@+id/city" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="City" /> 

     <EditText 
      android:id="@+id/state" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="State" /> 

     <EditText 
      android:id="@+id/gender" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="Gender(M/F)" /> 

     <EditText 
      android:id="@+id/remarks" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="Remarks" /> 
    </LinearLayout> 

</LinearLayout> 

</ScrollView> 
Смежные вопросы