I am trying to create a custom tabbed layout with a viewflipper. Therefore, I need two buttons side-by-side at the top of the screen. I have this. However, I am trying to get the viewFlipper content below these two buttons. Here is my current XML (which does not show the textviews)
<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>
Your LinearLayout
that contains the buttons has a layout_height="fill_parent"
. You need to set that to wrap_content
and also specify the orientation="vertical"
in the parent LinearLayout
. You'll also need to specify a layout_weight
for the view that you want to stretch to fill.
Because linearLayout01
LinearLayout
has its layout_height
set to fill_parent
, android is going to make it take up the reset of the screen. The content below that will not be visible at all because it is off the screen.
<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>
<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>
Generally, you have to ViewFlipper that contains the two or more layout that you want to display when, for example, click a buttom and whatever you want to see in all of screen, write outside of ViewPager tag.
来源:https://stackoverflow.com/questions/6333881/nested-viewflipper-layout