我创建了一个简单的 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/