Вложенный макет viewFlipper - PullRequest
2 голосов
/ 13 июня 2011

Я пытаюсь создать пользовательский макет с вкладками с помощью видоискателя.Поэтому мне нужны две кнопки рядом в верхней части экрана.У меня есть это.Тем не менее, я пытаюсь получить содержимое ViewFlipper ниже этих двух кнопок.Вот мой текущий XML (который не показывает текстовые представления)

        <LinearLayout
 android:id="@+id/linearLayout01" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:orientation="vertical"
 android:background="#FAFAFA"
 xmlns:android="http://schemas.android.com/apk/res/android">

    <LinearLayout 
        android:id="@+id/linearLayout02" 
        android:orientation="vertical" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content">
            <Button android:id="@+id/button1" android:text="button 1" android:layout_height="wrap_content" android:layout_width="0dip" layout_weight = ".5"/>
            <Button android:id="@+id/button2" android:text="button 2" android:layout_height="wrap_content" android:layout_width="0dip" layout_weight = ".5"/>
    </LinearLayout>
<RelativeLayout
    android:id="@+id/relativeLayout01"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_below="@id/linearLayout02">
    <ViewFlipper 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent" 
        android:id="@+id/viewFlipper01">

        <include 
            android:id="@+id/one" 
            layout="@layout/view_one" />
        <include 
            android:id="@+id/two" 
            layout="@layout/view_two" />

    </ViewFlipper>
    </RelativeLayout>
</LinearLayout>

Ответы [ 2 ]

3 голосов
/ 13 июня 2011

Ваш LinearLayout, содержащий кнопки, имеет layout_height="fill_parent". Вам необходимо установить значение wrap_content, а также указать orientation="vertical" в родительском элементе LinearLayout. Вам также необходимо указать layout_weight для представления, которое вы хотите растянуть для заполнения.

Поскольку linearLayout01 LinearLayout имеет layout_height, установленный на fill_parent, Android заставит его выполнить сброс экрана. Содержимое ниже, которое вообще не будет видно, потому что оно не на экране.

<LinearLayout
 android:id="@+id/linearLayout01" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:orientation="vertical" 
 xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
 android:id="@+id/linearLayout02" 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content">
    <Button android:id="@+id/button01" android:layout_height="wrap_content" android:text="Button 1" android:layout_width="0dip" android:layout_weight="1"></Button>
    <Button android:id="@+id/button02" android:layout_height="wrap_content" android:text="Button 2" android:layout_width="0dip" android:layout_weight="1"></Button>
</LinearLayout>

<RelativeLayout
 android:id="@+id/relativeLayout01" 
 android:layout_width="fill_parent" 
 android:layout_height="0dp"
 android:layout_weight="1">
    <ViewFlipper
        android:id="@+id/flipper01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView
        android:id="@+id/textview01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text"
        />  
        <TextView
        android:id="@+id/textview02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text2"
        />  

    </ViewFlipper>
    </RelativeLayout>
</LinearLayout>
0 голосов
/ 30 марта 2012
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/linearLayout01" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:orientation="vertical" >   

            <Button android:id="@+id/button01" 
    android:layout_height="wrap_content" 
    android:text="Button 1" 
    android:layout_width="0dip" 
    android:layout_weight="1" />

    <Button android:id="@+id/button02" 
    android:layout_height="wrap_content" 
    android:text="Button 2" 
    android:layout_width="0dip" 
    android:layout_weight="1" />

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


    <RelativeLayout
     android:id="@+id/relativeLayout01" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp"
     android:layout_weight="1">

        <!-- Screen 1: Wherever view you want to display on the first screen -->
    </RelativeLayout>
    <RelativeLayout
     android:id="@+id/relativeLayout02" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp"
     android:layout_weight="1">

        <!-- Screen 2: Wherever view you want to display on the second screen -->
    </RelativeLayout>

</ViewFlipper></LinearLayout> 

Как правило, вы должны ViewFlipper, который содержит два или более макета, который вы хотите отобразить, например, когда вы щелкнете по кнопке, и все, что вы хотите видеть на всем экране, напишите вне тега ViewPager.

...