Dav*_*lli 5 android touch-event drawerlayout
我的问题很简单.我可以在DrawerLayout的内容菜单中使用HorizontalScrollView吗?我的DrawerLayout看起来像这样:
<android.support.v4.widget.DrawerLayout
android:id="@+id/pnlMenu"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Main content view -->
<ListView
android:id="@+id/lst"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:fastScrollEnabled="true"
android:focusable="true"
android:focusableInTouchMode="true"
tools:listitem="@layout/item_layout" >
</ListView>
<!-- Content of menu -->
<FrameLayout
android:id="@+id/drawerFrame"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:clickable="true"
android:background="@color/black" >
<fragment
android:id="@+id/frag"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.test.TestFragment" />
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
在片段内部我有HorizontalScrollView但是当我尝试触摸它时没有任何事情发生,因为抽屉布局跟随我的手指.我认为禁用内容菜单中的触摸事件并仅在单击主内容视图时使DrawerLayout可关闭将解决我的问题.真的吗?如果没有,有人可以告诉我,我该怎么办?
谢谢.
基于此解决方案:https : //stackoverflow.com/a/7258579/452486
我已经能够HorizontalScrollView滚动。创建一个扩展类DrawerLayout:
public class AllowChildInterceptTouchEventDrawerLayout extends DrawerLayout {
private int mInterceptTouchEventChildId;
public void setInterceptTouchEventChildId(int id) {
this.mInterceptTouchEventChildId = id;
}
public AllowChildInterceptTouchEventDrawerLayout(Context context) {
super(context);
}
public AllowChildInterceptTouchEventDrawerLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mInterceptTouchEventChildId > 0) {
View scroll = findViewById(mInterceptTouchEventChildId);
if (scroll != null) {
Rect rect = new Rect();
scroll.getHitRect(rect);
if (rect.contains((int) ev.getX(), (int) ev.getY())) {
return false;
}
}
}
return super.onInterceptTouchEvent(ev);
}
}
Run Code Online (Sandbox Code Playgroud)
并添加您要拦截抽屉布局的触摸事件的子ID
AllowChildInterceptTouchEventDrawerLayout drawerLayout = (AllowChildInterceptTouchEventDrawerLayout) findViewById(R.id.layoutdrawer_id);
drawerLayout.setInterceptTouchEventChildId(R.id.horizontalscrollview_id);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1344 次 |
| 最近记录: |