YXTS122
YXTS122
2017-01-29 02:43
采纳率: 100%
浏览 2.2k

这个滑动式抽屉崩溃了

图片说明
SlidingDrawerActivity.java

 package com.example.slidingdrawerdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageButton;
import android.widget.SlidingDrawer;
import android.widget.TextView;

public class SlidingDrawerActivity extends Activity {
    private ImageButton imbg;
    private SlidingDrawer mDrawer;
    private TextView tv;
    private boolean flag;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sliding_drawer);
        imbg=(ImageButton)findViewById(R.id.handle);
        mDrawer=(SlidingDrawer)findViewById(R.id.slidingdrawer);
        tv=(TextView)findViewById(R.id.tv);

        mDrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {

            @Override
            public void onDrawerOpened() {
                // TODO Auto-generated method stub
                flag=true;
                imbg.setImageResource(R.drawable.abc_ic_search);
            }
        });

mDrawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {

            @Override
            public void onDrawerClosed() {
                // TODO Auto-generated method stub
                flag=false;
                imbg.setImageResource(R.drawable.abc_ic_search);
            }
        });

       mDrawer.setOnDrawerScrollListener(new SlidingDrawer.OnDrawerScrollListener() {

        @Override
        public void onScrollStarted() {
            // TODO Auto-generated method stub
            tv.setText("开始拖动"); 
        }

        @Override
        public void onScrollEnded() {
            // TODO Auto-generated method stub
            tv.setText("结束拖动");
        }
    });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.sliding_drawer, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

activity_sliding_drawer.xml
图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • as_csdn
    代码的灵魂是bug! 2017-01-29 03:50
    已采纳

    主要是在onCreate()中出错,第19行

    点赞 评论
  • as_csdn
    代码的灵魂是bug! 2017-01-29 05:55

    图片说明
    看这一行,你的SlidingDrawer是你自己写的,还是拖进去的?

    点赞 评论
  • YXTS122
    YXTS122 2017-01-29 08:47

    图片说明
    布局改为这样就可以了

    点赞 评论
  • YXTS122
    YXTS122 2017-01-29 08:59

    可以运行了。。。。。。。。。。。。图片图片

    点赞 评论

相关推荐