android - 删除 RecyclerView 项目之间的奇怪空间

标签 android android-layout android-recyclerview

我是 android 开发的新手,正在自学。我有一个非常奇怪的问题,在我的回收站 View 的每个项目之间都有奇怪的空间。我有以下内容:

我的回收站 View 是垂直的,具有 2 个跨度(列)的 GridView 布局。我一直在尝试的是:


布局代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginLeft="@dimen/size_five"
              android:layout_marginRight="@dimen/size_five"
              android:layout_marginTop="@dimen/size_fifteen"
              android:background="@color/blackColor"
              android:clickable="true"
              android:focusable="true"
              android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="50">

            <ImageView
                android:id="@+id/album_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/blackColor"
                />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/lowerline"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="15"
            android:background="@color/hotpinkColor"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="4"
                android:orientation="horizontal">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="@dimen/size_ten">

                    <TextView
                        android:id="@+id/album_title_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:gravity="left"
                        android:text="Album Title"
                        android:textColor="@color/whiteColor"
                        android:textSize="@dimen/size_eight"
                        android:textStyle="bold"/>
                </RelativeLayout>
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginRight="@dimen/size_ten"
                android:layout_weight="5"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">

                        <ImageView
                            android:id="@+id/downloader"
                            android:layout_width="@dimen/size_thirty_six"
                            android:layout_height="@dimen/size_thirty_six"
                            android:layout_centerInParent="true"
                            android:src="@drawable/donwloaderimager"/>
                    </RelativeLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">

                        <ImageView
                            android:id="@+id/setteraswall"
                            android:layout_width="@dimen/size_fourty"
                            android:layout_height="@dimen/size_fourty"
                            android:layout_centerInParent="true"
                            android:src="@drawable/setteras"/>
                    </RelativeLayout>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>

</LinearLayout>

屏幕截图 enter image description here

黑色空间显示我要删除的额外奇怪空间。

最佳答案

改变:

  <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="50">

            <ImageView
                android:id="@+id/album_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/blackColor"
                />
        </LinearLayout>

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="50">

            <ImageView
                android:id="@+id/album_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/blackColor"
                />
        </LinearLayout>

也就是将第二个父线性布局的高度改为wrap_content

关于android - 删除 RecyclerView 项目之间的奇怪空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39286410/

相关文章:

android - 在 Android Studio 中预览自定义字体

android - 无法访问 com.google.android.gms.internal.zzbql 的 zzbql 类文件未找到

java - LayoutInflater 膨胀 fragment

java - 如何做相机拍摄快照并存储到SD卡?

android - GridView 在 Android 中究竟是如何回收/重用 View 的?

安卓适配器 : using Linkedlist vs Arraylist

在新的 api 中不推荐使用 HttpConnectionParams 的 Android 多部分图像上传

java - 在 Bitmapfactory 中解码图像的特定区域?

具有回收 View 和详细信息 View 的 fragment 之间的 Android 共享元素转换

android - Kotlin - RecyclerView 项目中的 BottomNavigation- android.view.InflateException : Binary XML file line #91: Error inflating class