如何创建学习清单项目 [英] How to create leaning list items
问题描述
我有一个水平的RecyclerView
,看起来像这样(很明显)
I have a horizontal RecyclerView
which looks like this (obviously)
-------------------------------
| | | | | |
| 1 | 2 | 3 | 4 | 5 |
| | | | | |
-------------------------------
我想这样做:
------------------------------
| / / / / |
| 1 / 2 / 3 / 4 / 5 |
| / / / / |
-------------------------------
创建这样的RecyclerView
的最佳方法是什么?
What is the best way to create a RecyclerView
like this?
注意:我不是要创建倾斜的分隔线.我正在尝试创建一个倾斜的布局.靠倾斜是指蒙面不旋转.项目应具有match_parent
ImageView
和TextView
.两者都应看起来笔直,而不要旋转.还请注意第一项和最后一项.
Note: I'm not trying to create a leaning divider. I am trying to create a leaning layout. By leaning I mean masked not rotated. Items should have a match_parent
ImageView
and a TextView
. Both should look straight, not rotated. Also pay attention to the first and last item please.
以下是示例:
推荐答案
我建议您使用斜视
使用以下代码创建布局xml.此布局文件通过显示图像和文本在回收者"视图中呈现一行.
Create an layout xml with the below code. This layout file renders a single row in recycler view by displaying image and text.
<?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.
After writing custom adapter, you should prepare the RecyclerView as follows.
LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); // make it horizontal
recyclerView.setLayoutManager(layoutManager);
成功应用这些操作后,我得到了这样的图像.
After applying these operations successfully, I got an image like this.
此解决方案可能不是完美的解决方案.有一些缺陷点,例如 android:layout_marginLeft =-25dp" .至少它可以给你一个主意.
This solution may not be the perfect solution. There are some defective spots such as android:layout_marginLeft="-25dp". At least it can give you an idea.
这篇关于如何创建学习清单项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!