我正在尝试使用以下图层创建布局(从下到上):
当用户将屏幕滚动到右侧时,将更改4和4以显示不同的图像和信息。如果用户向左滚动,则将显示原始图层3和4。
我理解手势和动画是如何工作的,这不是问题,但我该如何创建布局呢?
感谢。
答案 0 :(得分:1)
我认为你的问题可能比我理解的要复杂得多,但这就是你想要的东西吗?
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/tabhost">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="@layout/some_xml_file"/>
</FrameLayout>
</LinearLayout>
</TabHost>
然后你将some_xml_file定义为:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/start_menu_background"
android:orientation="vertical"
android:id="@+id/just_a_test">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/techno"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<TableLayout android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true">
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello world."/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I'm another cell"/>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Just more stuff"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="And one last one"/>
</TableRow>
</TableLayout>
</RelativeLayout>
</RelativeLayout>
这为你提供了一个嵌套的布局,顶部有标签,持有一个带有自己背景的视图(外部RelativeLayout带有@ drawable / start_menu_background),然后那个有自己的背景(内部RelativeLayout带有@ drawable / techo),反过来有一个表格,里面有几排。
我唯一不满意的是,我不得不硬编码内部相对布局的高度,因为它似乎总是想要填充父级(无论我给它的背景图像的大小如何)。但你可以玩弄它,看看你得到了什么。
当然,要实现这一点,您必须为TabHosts提供所有代码才能工作。如果您之前没有这样做,请参阅这两个示例(official guide和another one)。