点击图片时没有显示导航抽屉(没有操作栏)

时间:2016-10-26 07:49:09

标签: java android xml

  

单击图像时。我想打开导航布局之类的   这个图像

     

现在,我通过在触摸屏上拖动来获取导航布局   从左到右。

     

我需要帮助,谢谢

     
    
      
        
          
            
              

链接图片:Sample image

            
          
        
      
    
  

----------------------------------------- ---------编译器---------------------------------------- ----------

compile 'com.android.support:design:24.2.1'

----------------------------------------- --------- activity_main.xml -------------------------------------- ------------     

<RelativeLayout
    android:id="@+id/HeaderLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    android:paddingBottom="15dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="85dp">

 //-------------------------------------------- Image that use when click
            <ImageView 
                android:id="@+id/imgview_menu"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_alignParentBottom="true"
                android:layout_alignParentTop="true"
                android:layout_marginRight="10dp"
                android:paddingTop="15dp"
                android:src="@drawable/more_menu" />
 //------------------------------------------------------------------

            <ImageView
                android:id="@+id/view2"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_marginRight="10dp"
                android:layout_toRightOf="@id/imgview_menu"
                android:elevation="12dp"
                android:innerRadius="0dp"
                android:shape="ring"
                android:thicknessRatio="1.9" />

        </RelativeLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="60dp">

                <ImageView
                    android:id="@+id/icon_wing"
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentEnd="false"
                    android:layout_alignParentRight="true"
                    android:src="@drawable/ic_wing" />

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_centerVertical="true"
                    android:layout_toLeftOf="@+id/icon_wing"
                    android:layout_toStartOf="@+id/icon_wing">

                    <TextView
                        android:id="@+id/txt_user"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:paddingBottom="10dp"
                        android:text="USER"
                        android:textColor="#fff"
                        android:textSize="18sp"
                        android:textStyle="bold" />

                </RelativeLayout>

            </RelativeLayout>

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="-10dp"
                android:paddingBottom="3dp"
                android:paddingTop="3dp"
                android:src="@drawable/main_line" />

            <TextView
                android:id="@+id/txt_user_point"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#fff"
                android:textSize="14sp" />

        </LinearLayout>

    </LinearLayout>

</RelativeLayout>

 //-------------------------------------------- Layout of Menu
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <FrameLayout
        android:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></FrameLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/drawer"
        android:layout_width="210dp"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:background="#e9e84e0e"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark"
        app:headerLayout="@layout/nav_header"
        app:menu="@xml/nav_menu" />

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

</RelativeLayout>

----------------------------------------- --------- nav_menu.xml -------------------------------------- ------------

  <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<group android:checkableBehavior="single">
    <item
        android:id="@+id/nav_profile"
        android:title="PROFILE"
        android:icon="@drawable/iconav_profile"/>
    <item
        android:id="@+id/nav_history"
        android:title="HISTORY"
        android:icon="@drawable/iconav_history"/>
    <item
        android:id="@+id/nav_article"
        android:title="ARTICLE"
        android:icon="@drawable/iconav_article"/>
    <item
        android:id="@+id/nav_feedback"
        android:title="FEEDBACK"
        android:icon="@drawable/iconav_feedback"/>
    <item
        android:id="@+id/nav_aboutus"
        android:title="ABOUT US"
        android:icon="@drawable/iconav_aboutus"/>
    <item
        android:id="@+id/nav_setting"
        android:title="SETTING"
        android:icon="@drawable/iconav_setting"/>
    <item
        android:id="@+id/nav_logout"
        android:title="LOGOUT"
        android:icon="@drawable/iconav_logout"/>
</group>
</menu>

----------------------------------------- --------- MainActivity.java -------------------------------------- ------------

public class MainActivity extends AppCompatActivity {

private DrawerLayout drawerLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    ImageView imageViewNav = (ImageView) findViewById(R.id.imgview_menu);
    imageViewNav.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            drawerLayout.openDrawer(GravityCompat.START);
        }
    });
}
}

1 个答案:

答案 0 :(得分:0)

    navigation_btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            mDrawerLayout.openDrawer(Gravity.LEFT);
        }
    });