0

当我制作两个滑动抽屉时,Onw Drawer 可以正常工作,但其他不是我所做的是

<?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#FCFCFC" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"
    android:layout_marginBottom="5px">
    <LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_gravity="left" >
        <SlidingDrawer     android:layout_gravity="left"
        android:orientation="horizontal" android:layout_width="wrap_content"   android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton" android:content="@+id/contentLayout" android:padding="10dip" android:layout_height="60dip">
            <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/slideHandleButton" android:background="@drawable/projectmain"></Button>
                <LinearLayout android:layout_width="wrap_content" android:id="@+id/contentLayout" android:orientation="horizontal" android:gravity="center" android:padding="10dip" android:background="@drawable/selector" android:layout_height="wrap_content">
                    <TextView android:background="@drawable/selector" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF" android:textStyle="bold" android:textSize="16sp" android:text="Unlock" android:gravity="center" />
                </LinearLayout>
        </SlidingDrawer>
    </LinearLayout>
    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#FCFCFC"
    android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"
    android:layout_marginBottom="5px">
    <LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_gravity="left" >
        <SlidingDrawer     android:layout_gravity="left"
        android:orientation="horizontal" android:layout_width="wrap_content"   android:id="@+id/SlidingDrawer1" android:handle="@+id/slideHandleButton1" android:content="@+id/contentLayout" android:padding="10dip" android:layout_height="60dip">
            <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/slideHandleButton1" android:background="@drawable/propertymain"></Button>
                <LinearLayout android:layout_width="wrap_content" android:id="@+id/contentLayout" android:orientation="horizontal" android:gravity="center" android:padding="10dip" android:background="@drawable/selector" android:layout_height="wrap_content">
                    <TextView android:background="@drawable/selector" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF" android:textStyle="bold" android:textSize="16sp" android:text="Unlock" android:gravity="center" />
                </LinearLayout>
        </SlidingDrawer>
    </LinearLayout>

我在 Java 上所做的是

我已经打开了两个抽屉

设置内容视图(R.layout.main);

            slideHandleButton = (Button) findViewById(R.id.slideHandleButton);
             slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);
                slideHandleButton1 = (Button) findViewById(R.id.slideHandleButton);
                 slidingDrawer1 = (SlidingDrawer) findViewById(R.id.SlidingDrawer);


                   slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {

                    @Override
                    public void onDrawerOpened() {
                        Intent intent=new Intent(CurrentActivity.this,New Activity.class);
                        startActivity(intent);
                    }
                    });

                    slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {

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



                    slidingDrawer1.setOnDrawerOpenListener(new OnDrawerOpenListener() {

                        @Override
                        public void onDrawerOpened() {
                            Intent intent=new Intent(CurrentActivity.this,NewActivity.class);
                            startActivity(intent);
                        }
                        });

                    slidingDrawer1.setOnDrawerCloseListener(new OnDrawerCloseListener() {

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

但是第二个滑动抽屉不起作用请帮助提前谢谢!

4

2 回答 2

1

改变这个

slidingDrawer1 = (SlidingDrawer) findViewById(R.id.SlidingDrawer);

 slidingDrawer1 = (SlidingDrawer) findViewById(R.id.SlidingDrawer1);

看起来您为这两个元素提供了相同的 id。

于 2012-12-10T06:44:46.857 回答
1

看看你的java代码,你为两个滑动抽屉使用了相同的id

于 2012-12-10T06:53:20.617 回答