安卓ViewFlipper作为滑动菜单

3

我正在尝试制作一个Android应用程序的侧滑菜单,使用ViewFlipper与两个布局,一个用于菜单,另一个用于内容。当内容布局中的按钮被触摸时,菜单应该从左侧滑入并覆盖80%的屏幕。目前我的做法是让菜单滑入80%,然后在动画之后显示100%的菜单。有没有什么办法可以使它正常工作呢?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <ViewFlipper android:id="@+id/viewflipper"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">   
<!-- content -->
        <LinearLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
                <Button android:id="@+id/bt_test"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="slide"/>
            <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="hello"/>
        </LinearLayout>
<!-- menu -->
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        </LinearLayout>
    </ViewFlipper>
</LinearLayout>

动画: 退出:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="0" android:toXDelta="80%" android:duration="500"/>
</set>

在:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="-100%" android:toXDelta="-20%" android:duration="500"/>
</set>

onclick:

            flipper.setInAnimation(MainActivity.this, R.anim.slide_in);
            flipper.setOutAnimation(MainActivity.this, R.anim.slide_out);
            flipper.showNext();
1个回答

2

你说得对,谢谢提供链接。我找了一些项目,但这个看起来真的很不错。 - Klaasvaak

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