问题描述:
用DrawerLayout实现的抽屉效果。现在想实现点击一个按钮,抽屉从右面滑出:
结果报错:java.lang.IllegalArgumentException: No drawer view found with gravity RIGHT
代码如下:
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mDrawerLayout.openDrawer(Gravity.RIGHT);
}
});
解决办法:
除了上面那段代码以外,还要在xml中,你的抽屉部分中增加:
android:layout_gravity="right"
然后就OK了。
总结:
下面是设置抽屉从哪个方向出现的官方文档:
Drawer positioning and layout is controlled using the android:layout_gravity attribute on child views corresponding to which side of the view you want the drawer to emerge from: left or right. (Or start/end on platform versions that support layout direction.)
http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html
中国文:
抽屉的位置和布局用android:layout_gravity属性控制,左面就left(或start),右面就right(end)。
(最好设置为start/end,好像left/right哪个版本以后就移除了)