【发布时间】:2020-04-10 20:40:14
【问题描述】:
我想要达到的目标:
我做了什么:
我有一个 1 到 5 列的按钮,当用户单击他想要的列数时,布局会发生变化,但所有卡片都粘在一起。到目前为止,这是我能够做到的:https://imgur.com/a/CL4FZhY
我的物品:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/video_preview"
android:layout_width="match_parent"
android:layout_height="194dp"
android:scaleType="centerCrop"
tools:src="@drawable/img_error_v1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/video_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceHeadline6"
android:maxLines="1"
tools:text="This is a really really really really really really really really really really really long title"
/>
<TextView
android:id="@+id/video_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:maxLines="1"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?android:attr/textColorSecondary"
tools:text="This is the URL for now"
/>
</LinearLayout>
</LinearLayout>
我的问题:
我怎样才能实现这种改变?我已阅读有关ItemDecoration 的信息,但我认为我无法更改我的项目的layout_height。我需要为每一列屏幕创建一个布局吗?
【问题讨论】:
-
澄清一下,您希望您的每个项目仍然具有完整宽度,但现在每行 2 个?
-
嗯,例如,在一列中我想要 100% 的宽度,对于 2 列 50% 可能会少一点以留出边距,3 列 33% 等等......高度会改变还有
-
它可以为您提供帮助。 answer
-
是的,我看到了
ItemDecoration示例,但问题是在我的一列中,图像的高度例如为 200dp,我希望 2 列的高度为 100dp
标签: android android-viewholder gridlayoutmanager