我正在尝试复制Facebook应用的新菜单滑块。创建从左侧进入的滑块非常简单。然而,Facebook应用程序采用Activity的布局并向右滑动,其左边的一小部分仍显示在屏幕的右侧。我对如何做到这一点感到有点困惑。有没有人有任何想法?
我能想到的最好的事情,我没有尝试过,是使用Display类来确定屏幕的宽度,将最外面的View的宽度设置为,并将其显示在右边的滑块(显然由RelativeView包裹)。
更新:我尝试了以下内容。
我最外面的View是RelativeLayout。在这个RelativeLayout里面有两个兄弟视图。它们都是LinearLayouts。第一个是包含侧栏的布局(在我的XML中,这是通过包括完成的)。第二个位于顶部,是一个包含Activity主体的布局(我想让用户正常看到它的屏幕)。
这是我的XML:
<?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="@color/black" >
<include
android:id="@+id/mainnew_slider"
layout="@layout/layout_slidermenu" />
<LinearLayout
android:id="@+id/mainfeed_mainlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/loginbg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="64dip"
android:background="@drawable/titlebar_background"
android:orientation="vertical"
android:padding="4dip" >
<ImageButton
android:id="@+id/mainfeed_slider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector_titlebar_button"
android:src="@drawable/sidebarico" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="@color/store_toolbar_bottom_border" />
</LinearLayout>
</RelativeLayout>
当用户点击ImageButton时,我使用一些动画代码使主布局向右移动。我用来动画主要布局的代码是:
AnimationSet set = new AnimationSet(true);
Animation animation = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,Animation.RELATIVE_TO_PARENT, 1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,Animation.RELATIVE_TO_PARENT, 0.0f
);
animation.setDuration(1000);
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(set, 0.0f);
LinearLayout main = (LinearLayout) findViewById(R.id.mainfeed_mainlayout);
main.setLayoutAnimation(controller);
当我单击滑块按钮时,主布局的两个子项向右滑动,而不是主布局本身(其背景保持静态)。动画完成后,所有内容都会快速恢复到原始位置。
我不明白为什么它没有移动整个主要布局并将其保持在静止的位置。