我創建了一個簡單的SliderDrawer。當點擊手柄時,它會正確打開,但再次單擊時不會關閉。我在類上設置了onclick,因此當單擊該句柄並且滑動拉鍊打開時,它會關閉但不起作用。任何想法爲什麼請?Slidingdrawer not closing
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();
}
}
});
}
}
sliding.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>
也許有相同的按鈕id和句柄不是一個好主意? – Blackbelt 2014-10-01 10:18:02
從我的理解是,該按鈕是滑動拉手的處理程序。如果我錯了,請糾正我。 – wayzz 2014-10-01 10:22:31
我的確是一個問題。 – Blackbelt 2014-10-01 10:24:50