Android: растянуть макет между двумя фиксированными LinearLayouts - PullRequest
5 голосов
/ 01 февраля 2012

это мой макет (изображение):

http://i.imgur.com/j8sqo.jpg


Что я хочу сделать, это сделать 1-й уровень LinearLayout 50dip (это уже нормально)Затем 3-й LinearLayout также высотой 50dip снизу вверх, а затем установите 2-й LinearLayout на место, оставленное между ними.Как мне это сделать?


Это мой XML:

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" >

</LinearLayout>


<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/linearLayout1"
    android:orientation="vertical" >

    <ViewFlipper
    android:id="@+id/viewFlipper1"
    android:layout_width="match_parent"
    android:layout_height="fill_parent" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/rain1" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/thunder1" />

    </ViewFlipper>

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout3"
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/linearLayout2">

</LinearLayout>

</RelativeLayout>

Ответы [ 6 ]

16 голосов
/ 01 февраля 2012

Оберните все три макета в вертикальный линейный макет и используйте вес макета из «1» на среднем макете:

<LinearLayout
    .
    .
    . 
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <LinearLayout 
        .
        .
        .
        android:layout_height="50dip">
    <LinearLayout 
        .
        .
        .
        android:layout_height="0dp"
        android:layout_weight="1">
    <LinearLayout 
        .
        .
        .
        android:layout_height="50dip">
</LinearLayout>
1 голос
/ 01 февраля 2012

Попробуйте это:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
              android:orientation="vertical" 
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent"
              >
    <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="50dip" 
        android:background="#FF00FF"    
        android:id="@+id/first"    
        />   
     <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="50dip" 
        android:background="#0000FF"
        android:id="@+id/last"    
        android:layout_alignParentBottom="true"         
       />        
     <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:background="#FFFFFF"
        android:layout_above="@id/last" 
        android:layout_below="@id/first"    
        >
        <ViewFlipper
            android:id="@+id/viewFlipper1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >       
                <ImageView
                    android:id="@+id/imageView1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:src="@drawable/rain1" />        
                <ImageView
                    android:id="@+id/imageView2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:src="@drawable/thunder1" />     
        </ViewFlipper>

    </LinearLayout>
</RelativeLayout>
1 голос
/ 01 февраля 2012

Преобразование LinearLayout в Относительный макет.определить относительное положение элемента.Ваша проблема будет решена

Или используйте вес в линейном расположении.определить вес 1.0 для второго линейного макета. а для верхнего родительского макета высота и ширина должны быть fill_parent

0 голосов
/ 01 февраля 2012

Я не добавил ваши отрисовки в этот код, но я считаю, что это должно решить вашу проблему:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" >

</LinearLayout>


<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/linearLayout1"
    android:layout_above="@+id/linearLayout3"
    android:orientation="vertical" >

    <ViewFlipper
    android:id="@+id/viewFlipper1"
    android:layout_width="match_parent"
    android:layout_height="fill_parent" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            />

    </ViewFlipper>

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout3"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true" >

</LinearLayout>


</RelativeLayout>
0 голосов
/ 01 февраля 2012

попробуйте поставить 3-й макет перед 2-м

<Relativelayout>
    <Linearlayout1>
    <Linearlayout3>
    <linearlayout2>
</Relativelayout>
0 голосов
/ 01 февраля 2012
LinearLayout layout;
layout.addView(child, 2);
...