gpt4 book ai didi

android - 如何创建学习列表项

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:19:45 24 4
gpt4 key购买 nike

我有一个水平的 RecyclerView 看起来像这样(显然)

-------------------------------
| | | | | |
| 1 | 2 | 3 | 4 | 5 |
| | | | | |
-------------------------------

我想这样做:

------------------------------
| / / / / |
| 1 / 2 / 3 / 4 / 5 |
| / / / / |
-------------------------------

创建这样的 RecyclerView 的最佳方法是什么?

注意:我并不是要创建一个倾斜的分隔线。我正在尝试创建一个倾斜的布局。通过倾斜我的意思是蒙面不旋转。项目应该有一个 match_parent ImageView 和一个 TextView。两者都应该看起来笔直,而不是旋转。另请注意第一项和最后一项。

这是一个示例:

sample

最佳答案

我建议你使用Squint

使用以下代码创建布局 xml。此布局文件通过显示图像和文本在回收站 View 中呈现单行。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:squint="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_marginLeft="-25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<com.intrusoft.squint.DiagonalView
android:id="@+id/diagonalView"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:scaleType="centerCrop"
squint:angle="10"
squint:diagonalDirection="bottom_to_top"
squint:gravity="right"/>

<TextView
android:background="#80000000"
android:layout_width="150dp"
android:layout_height="30dp"
android:gravity="center"
android:textColor="#FFF"
android:id="@+id/txtName"
android:layout_alignBottom="@+id/diagonalView"
android:layout_alignLeft="@+id/diagonalView"
android:layout_alignStart="@+id/diagonalView"/>

</RelativeLayout>

编写自定义适配器后,您应该按如下方式准备 RecyclerView。

 LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); // make it horizontal

recyclerView.setLayoutManager(layoutManager);

成功应用这些操作后,我得到了这样的图像。 enter image description here

此解决方案可能不是完美的解决方案。有一些缺陷点,例如 android:layout_marginLeft="-25dp"。至少它可以给你一个想法。

关于android - 如何创建学习列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41551094/

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