Android Sliding Drawer第一行始终可见

时间:2013-01-16 21:34:35

标签: android android-layout slidingdrawer

我已经创建了一个Android滑动抽屉,但当它被解除时,它是完全隐藏的。我正在寻找的行为是让抽屉的第一行始终可见。如果可能的话,尝试这个的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

这对我有用:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Button 1" />

    <SlidingDrawer
        android:id="@+id/slidingDrawer1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/button1"
        android:content="@+id/content"
        android:handle="@+id/handle" >

        <Button
            android:id="@+id/handle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Handle" />

        <ScrollView
            android:id="@+id/content"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <LinearLayout
                android:id="@+id/content1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:scrollbars="vertical" >

                <Button
                    android:id="@+id/button1a"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Button 1" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Button 2" />
            </LinearLayout>
        </ScrollView>
    </SlidingDrawer>

</RelativeLayout>

在主要活动中:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    actionsSlider = (SlidingDrawer) findViewById(R.id.slidingDrawer1);
    actionsSlider.setOnDrawerCloseListener(new OnDrawerCloseListener() {
        public void onDrawerClosed() {
            firstButton = (Button) findViewById(R.id.button1);
            firstButton.setVisibility(View.VISIBLE);

        }
    });

    actionsSlider.setOnDrawerScrollListener(new OnDrawerScrollListener() {

        public void onScrollStarted() {
            if (!actionsSlider.isOpened()) {
                findViewById(R.id.button1).setVisibility(View.GONE);
                firstButton = (Button) findViewById(R.id.button1a);
            }
        }

        @Override
        public void onScrollEnded() {
        }
    });
}