嵌套viewFlipper布局 [英] Nested viewFlipper Layout
问题描述
我想创建一个viewflipper的自定义标签布局。因此,我需要两个按钮侧由端在屏幕的顶部。我有这个。不过,我想获得viewFlipper含量低于这两个按钮。这是我当前的XML(不显示textviews)
<的LinearLayout
机器人:ID =@ + ID / linearLayout01
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直
机器人:后台=#FAFAFA
的xmlns:机器人=http://schemas.android.com/apk/res/android>
<的LinearLayout
机器人:ID =@ + ID / linearLayout02
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT>
<按钮机器人:ID =@ + ID / button1的机器人:文本=按钮1机器人:layout_height =WRAP_CONTENT机器人:layout_width =0diplayout_weight =0.5/>
<按钮机器人:ID =@ + ID /按钮2机器人:文本=按钮2机器人:layout_height =WRAP_CONTENT机器人:layout_width =0diplayout_weight =0.5/>
< / LinearLayout中>
< RelativeLayout的
机器人:ID =@ + ID / relativeLayout01
机器人:layout_width =FILL_PARENT
机器人:layout_height =0dp
机器人:layout_weight =1
机器人:layout_below =@ ID / linearLayout02>
< ViewFlipper
机器人:layout_height =FILL_PARENT
机器人:layout_width =FILL_PARENT
机器人:ID =@ + ID / viewFlipper01>
<包括
机器人:ID =@ + ID /一
布局=@布局/ view_one/>
<包括
机器人:ID =@ + ID /两个
布局=@布局/ view_two/>
< / ViewFlipper>
< / RelativeLayout的>
< / LinearLayout中>
您的LinearLayout
包含的按钮有一个 layout_height =FILL_PARENT
。您需要设置为 WRAP_CONTENT
,并指定方向=垂直
父的LinearLayout
。您还需要指定一个 layout_weight
为您要拉伸以填充视图。
由于 linearLayout01
的LinearLayout
有其 layout_height
设置为 FILL_PARENT
,Android是要使它占用屏幕的复位。在所有的,因为它是在屏幕下方的内容将不可见。
<的LinearLayout
机器人:ID =@ + ID / linearLayout01
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直
的xmlns:机器人=http://schemas.android.com/apk/res/android>
<的LinearLayout
机器人:ID =@ + ID / linearLayout02
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT>
<按钮机器人:ID =@ + ID / button01机器人:layout_height =WRAP_CONTENT机器人:文本=按钮1机器人:layout_width =0dip机器人:layout_weight =1>< /按钮>
<按钮机器人:ID =@ + ID / button02机器人:layout_height =WRAP_CONTENT机器人:文本=按钮2机器人:layout_width =0dip机器人:layout_weight =1>< /按钮>
< / LinearLayout中>
< RelativeLayout的
机器人:ID =@ + ID / relativeLayout01
机器人:layout_width =FILL_PARENT
机器人:layout_height =0dp
机器人:layout_weight =1>
< ViewFlipper
机器人:ID =@ + ID / flipper01
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
>
<的TextView
机器人:ID =@ + ID / textview01
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=文本
/>
<的TextView
机器人:ID =@ + ID / textview02
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=文本2
/>
< / ViewFlipper>
< / RelativeLayout的>
< / LinearLayout中>
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>
这篇关于嵌套viewFlipper布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!