gpt4 book ai didi

android - 删除 Android fragment 中回收器 View 上方不需要的空白区域

转载 作者:行者123 更新时间:2023-12-05 00:16:08 25 4
gpt4 key购买 nike

我的屏幕上出现了不需要的空白区域,如下所示。

Unwanted space

下面是我的回收器 View 中列表项的 xml 代码。

<?xml version="1.0" encoding="utf-8"?>

<androidx.cardview.widget.CardView
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="wrap_content"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="88dp">


<ImageView
android:id="@+id/ivWashListIcon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_dashboard_black_24dp" />

<TextView
android:id="@+id/tvWashListTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="Book"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@color/cardview_dark_background"
app:layout_constraintStart_toEndOf="@+id/ivWashListIcon"
app:layout_constraintTop_toTopOf="@+id/ivWashListIcon" />

<TextView
android:id="@+id/tvWashListDetail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="56dp"
android:text="TextView"
android:textAlignment="viewStart"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/tvWashListTitle"
app:layout_constraintTop_toBottomOf="@+id/tvWashListTitle" />
</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>

下面是 fragment 的代码。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content"
tools:context=".ui.wash.WashFragment">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvWashList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

这是 Activity 代码。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />

<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:defaultNavHost="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation" />

</androidx.constraintlayout.widget.ConstraintLayout>

在我的fragment.kt 文件中,我已初始化如下。

   var WashList: RecyclerView = root.findViewById(R.id.rvWashList)
layoutManager = LinearLayoutManager(activity)
WashList.layoutManager = layoutManager

adapter = WashListAdapter()
WashList.adapter = adapter
我曾尝试将layout_height参数更改为wrap_content和match_parent。但一切都没有改变。请帮忙。

最佳答案

问题出在您的 Activity XML 中的 paddingTop 上:android:paddingTop="?attr/actionBarSize">只需删除它即可。

关于android - 删除 Android fragment 中回收器 View 上方不需要的空白区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61834205/

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