2016-04-14 2 views
0

Моего макета выглядеть следующим образом:место две раскладки, кроме друг друг

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:background="@drawable/ightwall" 
    android:id="@+id/drawerlayout" 
    > 

    <ScrollView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:background="#6CEB87" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="my list"/> 
     </LinearLayout> 

    </ScrollView> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="#D5D4D4"> 

     <ImageView 
      android:id="@+id/mylist" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/createlist_mylist" 
      android:adjustViewBounds="true" 
      android:maxHeight="100dp" 
      android:maxWidth="100dp"/> 

     <ImageView 
     android:id="@+id/freeadd" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/createlist_freetext" 
     android:adjustViewBounds="true" 
     android:maxHeight="100dp" 
     android:maxWidth="100dp"/> 

     <ImageView 
      android:id="@+id/categoryadd" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/createlist_categorysearch" 
      android:adjustViewBounds="true" 
      android:maxHeight="100dp" 
      android:maxWidth="100dp"/> 

     <ImageView 
      android:id="@+id/favproductadd" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/createlist_favproduct" 
      android:adjustViewBounds="true" 
      android:maxHeight="100dp" 
      android:maxWidth="100dp"/> 



    </LinearLayout> 
</LinearLayout> 

Я хочу, чтобы два линейных слоев, чтобы выглядеть следующим образом:

the red layout will be for buttons ,and the green layout will be for changeable screens

Я развиваю в андроиде студии. Мне нужен красный макет, чтобы заполнить фиксированную ширину зеленой компоновкой, чтобы заполнить остальную часть экрана.

i want to get rid of the empty space i marked in red

ответ

0

установить android:weightSum="1" в основной компоновке и дать android:layout_weight (layout_width should be 0dp when you set layout_weight) для двух других макетов

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/drawerlayout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal" 
     android:weightSum="1" > 

     <ScrollView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="left" 
      android:layout_weight=".7" > 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:background="#6CEB87" 
       android:orientation="vertical" > 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="my list" /> 
      </LinearLayout> 
     </ScrollView> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
android:weightSum="4" 
      android:layout_gravity="right" 
      android:layout_weight=".3" 
      android:background="#D5D4D4" 
      android:orientation="vertical" > 

      <ImageView 
       android:id="@+id/mylist" 
       android:layout_width="wrap_content" 
       android:layout_height="0dp" 
      android:layout_weight="1" 
       android:adjustViewBounds="true" 
       android:maxHeight="100dp" 
       android:maxWidth="100dp" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/freeadd" 
       android:layout_width="wrap_content" 
       android:layout_height="0dp" 
      android:layout_weight="1" 
       android:adjustViewBounds="true" 
       android:maxHeight="100dp" 
       android:maxWidth="100dp" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/categoryadd" 
       android:layout_width="wrap_content" 
       android:layout_height="0dp" 
      android:layout_weight="1" 
       android:adjustViewBounds="true" 
       android:maxHeight="100dp" 
       android:maxWidth="100dp" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/favproductadd" 
       android:layout_width="wrap_content" 
       android:layout_height="0dp" 
      android:layout_weight="1" 
       android:adjustViewBounds="true" 
       android:maxHeight="100dp" 
       android:maxWidth="100dp" 
       android:src="@drawable/ic_launcher" /> 
     </LinearLayout> 

    </LinearLayout> 
+0

он работает спасибо, но если мне нужно красное расположение, чтобы обернуть его содержимое? что мне нужно изменить? Мне нужно, чтобы он был размером с кнопки внутри него –

+0

означает? объясните с помощью изображения –

+0

используйте match_parent вместо wrap_content в кнопке –

0

Добавьте android:layout_weight="1" ко второму LinearLayout, и установить ширину до 0

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:background="@drawable/ightwall" 
    android:id="@+id/drawerlayout" 
    > 

    <ScrollView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 

     ... 

    </ScrollView> 

    <LinearLayout 
     android:layout_width="0dp" // change 
     android:layout_weight="1" // add layout_weight 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="#D5D4D4"> 

     ... 

    </LinearLayout> 
</LinearLayout>