【问题标题】:Android DrawerLayout not showing primary contentAndroid DrawerLayout 不显示主要内容
【发布时间】:2016-03-17 23:59:54
【问题描述】:

我对 DrawerLayout 有疑问。我设法做了一个抽屉,这不是问题。但主要内容不显示。

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:context=".MainActivity">

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Holy Operating Systems!"
        android:textSize="24sp" />
</FrameLayout>

<fragment
    android:id="@+id/left_drawer"
    class="com.app.fragments.CustomFragment"
    android:layout_width="320dp"
    android:layout_height="match_parent"
    android:layout_gravity="start" /> </android.support.v4.widget.DrawerLayout>

我尝试了所有可能的组合。即使我删除片段主要内容仍然不显示。

有人能发现问题吗?

【问题讨论】:

  • 您有多个匹配的父母,尝试删除或更改一个?
  • @Rykuno,你到底是什么意思?根据developer.android:将您的主要内容视图定位为第一个孩子,宽度和高度为match_parent

标签: android drawerlayout


【解决方案1】:

上周,我遇到了这个问题,原因是你的宽度和高度 放。以下是我的代码。希望能给你一些建议。

`

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

    <!--mian content-->
    <FrameLayout
        android:id="@+id/flContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >


        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/im_MainImage"
            android:src="@mipmap/a"
            />

    </FrameLayout>


    <!--DrawLayout the content-->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/dlContent"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#ffffcc"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />


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

一开始,我没有设置layout_gravity,它不起作用。但我找到你 有它。我猜你的问题不在于drawlayout。

【讨论】:

    【解决方案2】:

    多么愚蠢愚蠢的事情,或者至少是我。

    问题是我在 AppTheme 下的 styles.xml 中有这个:

    &lt;item name="android:layout_gravity"&gt;center&lt;/item&gt;

    它不想在不显示任何错误的情况下那样工作。 以防万一有人做同样的事情。

    【讨论】:

      猜你喜欢
      • 2012-07-31
      • 1970-01-01
      • 2014-04-26
      • 1970-01-01
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-14
      相关资源
      最近更新 更多