有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java ListView与Android应用程序栏重叠

我的ListView位于页面边缘的应用程序栏上,我可能在布局文件中遇到问题。 (我使用了默认的安卓 studio活动,其中包含导航抽屉、应用程序栏等) 我使用框架布局将其用作子活动的父级,并在所有子活动中显示导航抽屉

导航总管总管。xml

<LinearLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:layout_width="match_parent"
    安卓:layout_height="@dimen/nav_header_height"
    安卓:background="@drawable/side_nav_bar"
    安卓:gravity="bottom"
    安卓:orientation="vertical"
    安卓:paddingBottom="@dimen/activity_vertical_margin"
    安卓:paddingLeft="@dimen/activity_horizontal_margin"
    安卓:paddingRight="@dimen/activity_horizontal_margin"
    安卓:paddingTop="@dimen/activity_vertical_margin"
    安卓:theme="@style/ThemeOverlay.AppCompat.Dark">

    <ImageView
        安卓:id="@+id/imageView"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:paddingTop="@dimen/nav_header_vertical_spacing"
        安卓:src="@安卓:drawable/sym_def_app_icon" />

    <TextView
        安卓:layout_width="match_parent"
        安卓:layout_height="wrap_content"
        安卓:paddingTop="@dimen/nav_header_vertical_spacing"
        安卓:text="MoviesInformer"
        安卓:textAppearance="@style/TextAppearance.AppCompat.Body1" />

    <TextView
        安卓:id="@+id/textView"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:text="testing" />

主要内容。xml

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    xmlns:app="http://schemas.安卓.com/apk/res-auto"
    xmlns:tools="http://schemas.安卓.com/tools"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".Activity.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <TextView
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:text="Movieys Informer" />
</RelativeLayout>

主应用程序。xml

<安卓.support.design.widget.CoordinatorLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    xmlns:app="http://schemas.安卓.com/apk/res-auto"
    xmlns:tools="http://schemas.安卓.com/tools"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
    安卓:fitsSystemWindows="true"
    tools:context=".Activity.MainActivity">

    <安卓.support.design.widget.AppBarLayout
        安卓:layout_width="match_parent"
        安卓:layout_height="wrap_content"
        安卓:theme="@style/AppTheme.AppBarOverlay">

        <安卓.support.v7.widget.Toolbar
            安卓:id="@+id/toolbar"
            安卓:layout_width="match_parent"
            安卓:layout_height="?attr/actionBarSize"
            安卓:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </安卓.support.design.widget.AppBarLayout>

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

    <!--<include layout="@layout/content_main" />-->

</安卓.support.design.widget.CoordinatorLayout>

主要活动。xml

<安卓.support.v4.widget.DrawerLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    xmlns:app="http://schemas.安卓.com/apk/res-auto"
    xmlns:tools="http://schemas.安卓.com/tools"
    安卓:id="@+id/drawer_layout"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
    安卓:fitsSystemWindows="true"
    tools:openDrawer="start">

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

    <!--<FrameLayout-->
        <!--安卓:id="@+id/content_frame"-->
        <!--安卓:layout_width="match_parent"-->
        <!--安卓:layout_height="match_parent" />-->

    <安卓.support.design.widget.NavigationView
        安卓:id="@+id/nav_view"
        安卓:layout_width="wrap_content"
        安卓:layout_height="match_parent"
        安卓:layout_gravity="start"
        安卓:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />


</安卓.support.v4.widget.DrawerLayout>

电影节活动。xml(在子活动中使用)

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:orientation="vertical" 安卓:layout_width="match_parent"
    安卓:layout_height="wrap_content">

    <ListView
        安卓:layout_width="fill_parent"
        安卓:layout_height="fill_parent"
        安卓:textAlignment="center"
        安卓:clickable="true"
        安卓:id="@+id/lwCinema"
        />


</LinearLayout>

谁能帮帮我吗

重复:

子活动中的listView位于应用程序栏的顶部(我想它被调用了),但仍然可以单击。我需要把它放在应用程序栏下面


共 (2) 个答案

  1. # 1 楼答案

    只需修改

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

    <FrameLayout
            android:id="@+id/content_frame"
            android:layout_marginTop="?android:attr/actionBarSize"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
  2. # 2 楼答案

    正确的方法不是使用marginTop=“?android:attr/actionBarSize”,而是将app:layout_behavior属性添加到框架布局中。此属性使框架布局始终位于工具栏下方

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    

    别忘了添加xmlns:app=”http://schemas.android.com/apk/res-auto“标记到布局的根目录