我的应用程序中有一个错误,我不知道如何解决它。我的应用程序有两个左右导航抽屉。右侧导航抽屉工作正常,但当左侧导航抽屉打开并在其中单击时,它会检测到我在主布局中单击。为了更好地理解,我给你看了这张照片:
我希望我能解释清楚。
这是我的代码:
的布局。
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0" />
<!-- Left -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="400dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/black_main"
android:choiceMode="singleChoice"
android:divider="#555555"
android:dividerHeight="1dp"
android:listSelector="@drawable/menu_list_selector" />
<!-- Right -->
<LinearLayout
android:id="@+id/right_drawer"
android:layout_width="400dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:background="@color/white_opaque"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/container_filtros"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/cnt_filtros"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include
android:id="@+id/filtros"
layout="@layout/menu_filtros" />
</LinearLayout>
<LinearLayout
android:id="@+id/cnt_categorias"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone" >
<include
android:id="@+id/lstCategorias"
layout="@layout/filter_categorias" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Java代码:
private void setSlides(Bundle savedInstanceState) {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerViewRight = (View) findViewById(R.id.right_drawer);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
mFilterList = (ListView) findViewById(R.id.list_filter);
mRightDrawerList = (ListView) findViewById(R.id.right_drawer_list);
mOrdenarList = (ListView) findViewById(R.id.list_ordenar);
mDistanceList = (ListView) findViewById(R.id.list_distance);
// LEFT SLIDING
navDrawerItems = new ArrayList<MoNavMenu>();
// Items
navDrawerItems.add(new MoNavMenu("DIIN", R.drawable.slide_img_home));
navDrawerItems.add(new MoNavMenu("¿QUÉ HACER", R.drawable.slide_img_quehacer));
navDrawerItems.add(new MoNavMenu("¿A DÓNDE IR?", R.drawable.slide_img_dondeir));
navDrawerItems.add(new MoNavMenu("DESCUBRE", R.drawable.slide_img_descubre));
navDrawerItems.add(new MoNavMenu("LEE TU MAPA", R.drawable.slide_img_leermapa));
navDrawerItems.add(new MoNavMenu("CAPTURA DIIN", R.drawable.slide_img_captura));
navDrawerItems.add(new MoNavMenu());
navDrawerItems.add(new MoNavMenu("CONFIGURACIÓN", R.drawable.slide_img_config));
// RIGHT SLIDING
navRightDrawerItems = new ArrayList<MoNavCategory>();
navFilters = new ArrayList<MoNavFilter>();
navFilters.add(new MoNavFilter("CATEGORÍA", filterCategoria));
adapter = new AdNavMenu(getApplicationContext(), navDrawerItems);
adapterR = new AdNavRight(this, navRightDrawerItems);
adapterFilter = new AdFilterHome(this, navFilters);
mDrawerList.setAdapter(adapter);
mFilterList.setAdapter(adapterFilter);
mRightDrawerList.setAdapter(adapterR);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer,
R.string.app_name,
R.string.app_name
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
displayView(0);
}
}
答案 0 :(得分:9)
您必须在滑动窗格布局中编写android:clickable="true"
。
答案 1 :(得分:1)
您有右侧抽屉的framelayout,因此如果您的顶部窗口小部件没有消耗该用户点击,它会将您的点击转移到底部窗口小部件。所以你需要添加空视图并设置onclick监听器并在那里消费点击。按钮不会再被点击。