【问题标题】:Android app main content is above title barAndroid app主要内容在标题栏上方
【发布时间】:2017-03-29 04:33:51
【问题描述】:

我正在 Visual Studio 中构建一个 android 应用程序。在我的 feed.axml 文件中,我的主体内容浮动在我的标题栏上方。它应该在标题栏下方。我很困惑为什么我的代码会这样做。

my android app as of this post 此图像中显示在标题栏上方的内容是卡片和大文本。如果有人知道如何在标题栏下方浮动这些元素,请告诉我。

任何帮助将不胜感激

这是我的 xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_height="match_parent"
    android:layout_width="fill_parent"
    android:fitsSystemWindows="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.v7.widget.CardView
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/cardView1" />
        <TextView
            android:text="hello world"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView1" />
        <include
            layout="@layout/toolbar" />
    </LinearLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_height="match_parent"
        android:layout_width="300dp"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header" />
</android.support.v4.widget.DrawerLayout>

【问题讨论】:

  • 您有&lt;CardView&gt;&lt;TextView&gt; 列在垂直&lt;LinearLayout&gt; 的工具栏&lt;include&gt; 之前。如果您希望它们在下方,请将它们移到其后面。

标签: android xml layout xamarin.android


【解决方案1】:

用这个替换你的代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
  layout="@layout/toolbar" />
<android.support.v4.widget.DrawerLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_height="match_parent"
    android:layout_width="fill_parent"
    android:fitsSystemWindows="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.v7.widget.CardView
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/cardView1" />
        <TextView
            android:text="hello world"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView1" />

    </LinearLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_height="match_parent"
        android:layout_width="300dp"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header" />
</android.support.v4.widget.DrawerLayout>

LinearLayout 线性放置它的子元素,所以你需要做这样的事情。 您还可以将工具栏放在 CardView 之前的某个位置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-11
    • 2017-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多