2016-10-25 16 views
0

如果我設置的順序的onclick事件在圖片中看到 - >Image的RelativeLayout這麼想的,因爲得到的DrawerLayout

的DrawerLayout是content_main 而DrawerLayout下繪製這麼想的獲得OnClickEvents

如果我設置的順序:第一content_main然後drawer_layout

的DrawerLayout繪製在content_main但content_main沒有得到的onclick事件

在這裏我activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
 

 
<RelativeLayout 
 
    xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent"> 
 

 

 
    <android.support.v7.widget.Toolbar 
 
     android:id="@+id/toolbar" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="?attr/actionBarSize" 
 
     android:background="?attr/colorPrimary" 
 
     android:elevation="4dp" 
 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
 

 

 
    <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" 
 
     android:layout_below="@+id/toolbar" 
 
     android:clickable="true"> 
 
     <!--The main content view--> 
 
     <!--The navigation drawer--> 
 
     <ListView android:id="@+id/left_drawer" 
 
      android:layout_width="240dp" 
 
      android:layout_height="match_parent" 
 
      android:layout_gravity="start" 
 
      android:choiceMode="singleChoice" 
 
      android:divider="@android:color/transparent" 
 
      android:dividerHeight="0dp" 
 
      android:background="#fff" 
 
      android:visibility="visible"/> 
 

 
    </android.support.v4.widget.DrawerLayout> 
 

 
    <RelativeLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:layout_below="@+id/toolbar" 
 
     android:id="@+id/content_main" 
 
     android:focusable="false"> 
 

 
    </RelativeLayout> 
 

 

 
</RelativeLayout>

的問題是隻的佈局得到OnClickEvents之一。 我如何做這兩個佈局得到OnClickEvents。

對不起,我的英文。

+0

@AbdulAhad相反,這是一個'RelativeLayout'因此後者添加視圖 - 'content_main'在上述代碼 - 是在頂部顯示的一個,並因此消耗了'的onClick事件。 – MohanadMohie

+0

請解釋您希望點擊行爲如何。如果你想讓兩個佈局具有相同的'onClick',給它們相同的'OnClickListener'。 – MohanadMohie

+0

我分散注意力之後。我找到了解決方案。我將content_main佈局放入DrawerLayout。感謝您的努力。 – Epig

回答

0

您應該將content_main放入DrawerLayout中,如圖所示。

Picture

相關問題