利用DrawerLayout和触摸事件分发实现抽屉侧滑效果-创新互联
本文实例为大家分享了DrawerLayout和触摸事件分发实现抽屉侧滑效果的具体代码,供大家参考,具体内容如下
网站设计、成都网站建设,成都做网站公司-创新互联已向上千多家企业提供了,网站设计,网站制作,网络营销等服务!设计与技术结合,多年网站推广经验,合理的价格为您打造企业品质网站。效果展示
还是看代码实在,直接上菜了。
1.MainActivity的代码:
public class MainActivity extends AppCompatActivity implements MyDraweLayout.GetPositionCallback { private ListimageList; private ViewPager viewPager; private MyAdapter adapter; private MyDraweLayout myDraweLayout; private int currentPosition; @Override protected void onCreate (Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); viewPager = (ViewPager) findViewById(R.id.viewpager); myDraweLayout = (MyDraweLayout) findViewById(R.id.mydrawelayout); initdata(); adapter = new MyAdapter(this, imageList); myDraweLayout.setCallback(this); viewPager.setAdapter(adapter); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { currentPosition=position; } @Override public void onPageScrollStateChanged(int state) { } }); } private void initdata() { imageList = new ArrayList (); ImageView imageView = new ImageView(this); imageView.setImageResource(R.mipmap.ic_launcher); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageList.add(imageView); imageView = new ImageView(this); imageView.setImageResource(R.mipmap.ic_launcher); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageList.add(imageView); imageView = new ImageView(this); imageView.setImageResource(R.mipmap.ic_launcher); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageList.add(imageView); imageView = new ImageView(this); imageView.setImageResource(R.mipmap.ic_launcher); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageList.add(imageView); } @Override public int position() { return currentPosition;//TODO 通过接口回调把当前位置传到MyDraweLayout中 } }
文章标题:利用DrawerLayout和触摸事件分发实现抽屉侧滑效果-创新互联
文章起源:http://ybzwz.com/article/isseh.html