在我的应用程序中,我实现了SlidingDrawer,但它无法正常工作。我在任何地方都错了。
Drawer = (SlidingDrawer) findViewById(R.id.drawer);
Drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
@Override
public void onDrawerOpened() {
Toast.makeText(getApplicationContext(),"Drawer Opened", Toast.LENGTH_SHORT).show();
}
});
类似地,setOnDrawerCloseListener
也不起作用,我的XML文件是:
<SlidingDrawer android:id="@+id/drawer"
android:background="@null" android:layout_height="fill_parent"
android:handle="@+id/handle" android:content="@+id/chat_history_container"
android:layout_width="fill_parent">
<ImageView android:id="@+id/handle" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/chat_icon" />
<RelativeLayout android:id="@+id/chat_history_container"
android:layout_width="fill_parent" android:layout_height="wrap_content">
//Some TextViews here
</RelativeLayout>
</SlidingDrawer>
答案 0 :(得分:0)
试用此代码: Xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:gravity="bottom"
android:background="@drawable/androidpeople">
<SlidingDrawer android:layout_width="wrap_content"
android:id="@+id/SlidingDrawer"
android:handle="@+id/slideHandleButton" android:content="@+id/contentLayout"
android:padding="10dip" android:layout_height="250dip">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/slideHandleButton" android:background="@drawable/closearrow">
</Button>
<LinearLayout android:layout_width="wrap_content" android:id="@+id/contentLayout" android:orientation="vertical" android:gravity="center|top" android:padding="10dip" android:background="#C0C0C0" android:layout_height="wrap_content">
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Content"></Button>
<Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Content"></Button>
<Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Content"></Button>
Java代码:
public class slidingDrawerExample extends Activity {
Button slideHandleButton;
SlidingDrawer slidingDrawer;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
slideHandleButton = (Button) findViewById(R.id.slideHandleButton);
slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);
slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
@Override
public void onDrawerOpened() {
slideHandleButton.setBackgroundResource(R.drawable.openarrow);
}
});
slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
@Override
public void onDrawerClosed() {
slideHandleButton.setBackgroundResource(R.drawable.closearrow);
}
});
}
}
检查此链接以供参考Sliding Drawer ...