我在尝试复制Facebook应用程序的新菜单滑块。创建从左侧进入的滑块很简单。不过,Facebook应用会采用活动的布局并将其向右滑动,其左侧边缘的一小部分仍显示在屏幕的右侧。我对如何做到这一点有些困惑。有没有人有任何想法?屏幕外的偏移活动布局
我能想到的,我没有尝试过的最好的事情是使用Display类来确定屏幕的宽度,将最外侧视图的宽度设置为该宽度并将其显示在右侧滑块(显然由一个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);
当我点击滑块按钮,主要布局向右滑动的两个孩子,但不是主要的布局本身(其背景保持静态)。动画完成后,所有内容都会恢复到原始位置。
我不明白为什么它没有移动整个主布局并将其保持在其休息的地方。
我还是有点迷路。我有一个包含两个LinearLayout子项的RelativeLayout。其中一个孩子是我的滑块。另一个是我的主要布局。我已经将主布局上的layout_toRightOf设置为滑块的ID。该应用只是崩溃。如果我删除layout_toRightOf,TranslateAnimation会将滑块带入视图中,但主布局不会像我期望的那样从屏幕右侧推出。 – Andrew 2011-12-13 20:09:21