0

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

4

1 回答 1

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() {
        }
    });
}
于 2013-01-17T11:20:03.653 回答