安卓视图翻转器自定义绘制

4

我对ViewFlipper有几个疑问。

我正在使用ViewFlipper通过scroll_left动画切换到另一个视图。

我在ViewFlipper中放置了2个LinearLayouts。

现在我想要4个视图....

比如第一个视图包含3个按钮。

点击第一个按钮 -> 第二个视图滚动进入 -> 返回按下第一个视图滚动 回来 点击第二个按钮 -> 第三个视图滚动进入 -> 返回按下第一个视图滚动 回来 点击第三个按钮 -> 第四个视图滚动进入 -> 返回按下第一个视图滚动 回来

那么,我将如何安排4个LinearLayouts以在flipNext中工作....

现在理想情况下,第2、3、4个视图仅处于第二级导航中。当第2、3、4个视图出现时,我想画一条线、点或矩形,但它们都是不同的形状。那么绘制的方法是什么?

1个回答

2

您可以按照以下方式进行:

<LinearLayout
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/header">
<TextView
android:id="@+id/header_text"
android:gravity="center"
android:textSize="25px"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:layout_width="fill_parent"
    android:paddingBottom="5px">
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/flipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <include android:id="@+id/chatView"  layout="@layout/chat_view" />
    <include android:id="@+id/userView"  layout="@layout/user_view" />
    <include android:id="@+id/gameView" layout="@layout/game_view"/>
    <include android:id="@+id/allGamesView" layout="@layout/all_game_view" />
</ViewFlipper>

您可以看到,我定义了一个文本视图,该视图每次显示。 ViewFlipper位于此标题TextView下方。因此,您只需翻转整个视图的一部分即可。要从视图1翻转到2,只需调用

flipper.showNext();

执行1到3次翻转,只需调用以下代码:
flipper.showNext();
flipper.showNext();

从 4 切换到 2,你需要调用以下代码:

flipper.showPrevious();
flipper.showPrevious();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接