首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SlidingDrawer不工作

SlidingDrawer不工作
EN

Stack Overflow用户
提问于 2011-04-01 19:44:54
回答 1查看 2.9K关注 0票数 0

在我的应用程序中,我实现了SlidingDrawer,但它不起作用。我在任何地方都错了吗。

代码语言:javascript
复制
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文件是:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-01 19:54:46

尝试此代码: Xml代码:

代码语言:javascript
复制
    <?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代码:

代码语言:javascript
复制
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...

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5512884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档