java - 滑动抽屉未关闭

标签 java android

我创建了一个简单的 SliderDrawer。单击 handle 时,它会正确打开,但再次单击时,它不会关闭。我在类上设置了 onclick,因此当单击 handle 并且滑动抽屉打开时,它会关闭但不起作用。知道为什么吗?

slider .java

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.SlidingDrawer;

@SuppressWarnings("deprecation")
public class Slider extends Activity {

    SlidingDrawer sd;
    Button handler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sliding);
        sd = (SlidingDrawer) findViewById(R.id.slidingD);
        handler = (Button) findViewById(R.id.handle);
        handler.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(sd.isOpened() == true){
                    sd.animateClose();
                }
            }
        });
    }
}

滑动.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <SlidingDrawer
        android:id="@+id/slidingD"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:content="@+id/content"
        android:handle="@+id/handle" >
        <!-- android:handle calls the button (Handle) -->
        <!-- android:content calls the linear layout (Hidden Content) -->

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

        <LinearLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <CheckBox
                android:id="@+id/cSlideable"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="CheckBox" />
        </LinearLayout>
    </SlidingDrawer>

</LinearLayout>

最佳答案

改用抽屉监听器,它将减轻您处理不同状态的压力

mDrawerLayout.setDrawerListener(mListener);

https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html

关于java - 滑动抽屉未关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26139064/

相关文章:

java - 如何检查 ISO 日期字符串中是否存在偏移量

java - 在 CompletableFuture 回调中为类成员属性设置值是否线程安全?

android - 如何为 SuperSLiM 库编译 JAR?

android - react native AppState 在 Android 上没有 'inactive' 状态

java - 如何从 Android 应用程序强制连接到特定的 GSM 网络

安卓 Facebook 分享 : activity not found

android:检查应用程序是否更新或新用户

java - 在java swing中输入文本字段后自动制表符?

java - 如何在通过java创建的Excel工作表中设置整数值?

java - 如何使用 jSTL 从 url 获取一些值