【问题标题】:How to show my layout below the navigation drawer?如何在导航抽屉下方显示我的布局?
【发布时间】:2015-06-01 09:29:43
【问题描述】:

我在this 之后实现了抽屉式导航。添加我的 xml 后,活动未在中心位置显示 imageview。 以下是我的xml文件

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#2ba886"
    app:contentInsetEnd="0dp"
    app:contentInsetStart="0dp" >
</android.support.v7.widget.Toolbar>

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

      <!--   <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#fff" > -->

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/logo_img" 
                />

    </FrameLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="left|start"
        android:background="#fff" >

        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#fff"
            android:divider="#eee"
            android:dividerHeight="1dp" />
    </RelativeLayout>
</android.support.v4.widget.DrawerLayout>

问题是 Imageview layout_gravity 选项没有出现 请帮忙。。

【问题讨论】:

  • ImageView 默认对齐到 FrameLayout 的左上角。此外,您应该有一个精确的度量 - 例如240dp - 用于抽屉的RelativeLayout 的layout_width
  • @MikeM。如何在活动视图的导航抽屉下方显示不同的视图(例如按钮、文本视图、编辑文本)
  • “下面”是什么意思?朝向屏幕底部?还是在抽屉后面按 z 顺序排列?
  • @MikeM。参考我附加的图像..在 xml 中添加按钮和图像视图的位置
  • 如果您的意思是要将它们放在抽屉后面的灰色区域中,您可以将它们放在 FrameLayout 中。不过,FrameLayouts 并不是真的要灵活地容纳多个孩子,因此您可以更改它,或者在其中嵌套另一种类型的 ViewGroup。

标签: android android-layout navigation drawer


【解决方案1】:

这样做

<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 to display Fragments -->

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

        <include layout="@layout/actionbar" />

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

    <!-- Listview to display slider menu -->

    <LinearLayout
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        android:orientation="vertical" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text="Home"
            android:textColor="@android:color/black"
            android:textSize="20sp" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/black" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text="Android"
            android:textColor="@android:color/black"
            android:textSize="20sp" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/black" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text="Sitemap"
            android:textColor="@android:color/black"
            android:textSize="20sp" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/black" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text="About"
            android:textColor="@android:color/black"
            android:textSize="20sp" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/black" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text="Contact Me"
            android:textColor="@android:color/black"
            android:textSize="20sp" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/black" />

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center_horizontal"
            android:padding="10dp"
            android:src="@drawable/ic_launcher" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/black" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button1" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button2" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button3" />
    </LinearLayout>

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

手动删除列表视图并设置抽屉项目。

【讨论】:

    【解决方案2】:

    试试这个:在 linearlayue 中获取图像视图并设置重力

     <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
    
          <!--   <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#fff" > -->
    
    <LinearLayout android:id="@+id/..."
            android:layout_width="..."
            android:layout_height="fill_parent"
            android:layout_gravity="start"
          android:orientation="vertical"
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/logo_img" 
                    />
    </Linearlayout>
    
        </FrameLayout>
    

    【讨论】:

      【解决方案3】:
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent" >
      
      <android.support.v4.widget.DrawerLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/drawer_layout"
          android:layout_above="@+id/linearLayout1"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="#FFFFFF" >
      
          <!-- The main content view -->
      
          <FrameLayout
              android:id="@+id/content_frame"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" >
          </FrameLayout>
      
          <!-- The navigation drawer -->
      
          <ListView
              android:id="@+id/left_drawer"
              android:layout_width="240dp"
              android:layout_height="match_parent"
              android:layout_gravity="start"
              android:background="#555555"
              android:choiceMode="singleChoice"
              android:divider="#666"
              android:dividerHeight="1dp" />
      </android.support.v4.widget.DrawerLayout>
      <LinearLayout
          android:id="@+id/linearLayout1"
          android:layout_width="wrap_content"
          android:layout_height="60dp"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="0dp"
          android:orientation="horizontal" >
      
          <include layout="@layout/tab_bar" />
      </LinearLayout>
      </RelativeLayout>
      

      请使用这可能会有所帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-22
        • 2018-10-16
        • 2020-07-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多