gpt4 book ai didi

java - ListView 与应用程序栏重叠 - Android

转载 作者:行者123 更新时间:2023-12-01 18:04:28 24 4
gpt4 key购买 nike

我的ListView位于页面边缘的应用程序栏上,我可能在布局文件中存在问题。(我使用了默认的 android studio Activity ,其中包含抽屉导航、应用程序栏...)我使用了frameLayout 将其用作子 Activity 的父级,并在所有子 Activity 中显示抽屉导航。

nav_header_main.xml

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

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

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

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

content_main.xml

<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Activity.MainActivity"
tools:showIn="@layout/app_bar_main">

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

app_bar_main.xml

<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Activity.MainActivity">

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

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

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

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

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

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

activity_main.xml

<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" />

<!--<FrameLayout-->
<!--android:id="@+id/content_frame"-->
<!--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:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />


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

cinema_activity.xml(在子 Activity 中使用)

 <?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="wrap_content">

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


</LinearLayout>

有人可以帮我吗?

重复:

子 Activity 中的listView位于应用程序栏的顶部(我认为它被称为),但它仍然是可单击的。我需要将它放在应用栏下方。

最佳答案

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

<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" 标签添加到布局的根目录。

关于java - ListView 与应用程序栏重叠 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37807328/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com