【问题标题】:Add footer layout in navigation drawer在导航抽屉中添加页脚布局
【发布时间】:2017-03-26 14:25:20
【问题描述】:

5.5 英寸屏幕设备下方导航抽屉中菜单项的注销布局重叠

这在 5.5 英寸屏幕设备上看起来很完美

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@drawable/drawer_bg"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:itemTextColor="@color/grey_text"
        app:menu="@menu/activity_main_drawer">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="#50000000"
            android:clickable="true"
            android:orientation="vertical">

            <TextView
                android:id="@+id/nav_logout"
                android:layout_width="match_parent"
                android:layout_height="44dp"
                android:gravity="center"
                android:text="Logout"
                android:textColor="@color/colorAccent"
                android:textSize="16sp" />

        </LinearLayout>

    </android.support.design.widget.NavigationView>


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

这是我的 xml 代码。我的问题是如何让注销布局成为 5.5 英寸以下屏幕中导航抽屉的一部分,以便用户可以滚动菜单以到达底部以获取注销按钮。

谢谢。

【问题讨论】:

    标签: android xml user-interface


    【解决方案1】:

    如果您尝试像其他人一样将注销添加到导航列表中的项目并在向下滚动时查看注销,如果我做对了,请尝试使用 ListView 而不是单独使用注销并将注销添加为项目之一.我没有看到您如何添加其他项目的 JAVA 代码。希望它能解决你的问题。这是一个示例代码:

    `

    <android.support.design.widget.NavigationView
            android:id="@+id/navi"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:menu="@menu/main_menu"
            android:background="#CCCCCC">
            <ListView
                 xmlns:android="http://schemas.android.com/apk/res/android"
                 xmlns:tools="http://schemas.android.com/tools"
                 android:id="@+id/expnavimenu"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:choiceMode="singleChoice"
                 android:dividerHeight="2dp"
                 android:groupIndicator="@color/white"
                 android:listSelector="@color/greyc4"
                 android:childIndicator="@color/greyc4"
                 android:background="@color/white"
                 android:layout_marginTop="5dp"
                 android:layout_marginBottom="5dp"/>
     </android.support.design.widget.NavigationView>
    

    `

    【讨论】:

      【解决方案2】:

      这个解决方案适合我:

      <com.google.android.material.navigation.NavigationView
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_gravity="start">
      
              <androidx.core.widget.NestedScrollView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:fillViewport="true"
                  android:scrollbars="vertical">
      
                  <LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:orientation="vertical">
      
                      <com.google.android.material.navigation.NavigationView
                          android:id="@+id/nav_view"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:layout_gravity="start"
                          android:overScrollMode="never"
                          app:elevation="0dp"
                          app:headerLayout="@layout/nav_header_main"
                          app:itemIconTint="?attr/colorArrowDown"
                          app:menu="@menu/navigation_drawer_menu" />
      
                      <LinearLayout
                          android:id="@+id/spacer_to_bottom"
                          android:layout_width="match_parent"
                          android:layout_height="0dp"
                          android:layout_weight="1"
                          android:orientation="vertical" />
      
                      <LinearLayout
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_gravity="bottom"
                          android:background="@drawable/background_white"
                          android:orientation="vertical"
                          android:padding="16dp">
      
                          <ImageView
                              android:layout_width="match_parent"
                              android:layout_height="32dp"
                              android:src="@drawable/ic_telegram" />
      
                          <TextView
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:layout_marginTop="10dp"
                              android:gravity="center"
                              android:text="@string/titleChanelTelegram"
                              android:textSize="@dimen/textSizeTiny" />
      
                          <TextView
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:layout_marginTop="10dp"
                              android:gravity="center"
                              android:text="@string/telegramID"
                              android:textColor="@color/colorBlack"
                              android:textSize="@dimen/textSizeNormal" />
      
                          <TextView
                              android:id="@+id/txt_version"
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:layout_marginTop="10dp"
                              android:gravity="center"
                              android:textSize="10dp" />
                      </LinearLayout>
                  </LinearLayout>
              </androidx.core.widget.NestedScrollView>
          </com.google.android.material.navigation.NavigationView>
      

      我希望它能解开这个结

      【讨论】:

        【解决方案3】:

        对于点击或处理页脚:

        NavigationView navigationView = (NavigationView) findViewById(R.id.navi);
            ListView footerLV = (ListView) navigationView.findViewById(R.id.expnavimenu);
            footerLV.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(MainActivity.this, "Footer is clicked", Toast.LENGTH_SHORT).show();
                }
            });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-01-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多