我正在尝试创造这种效果
我正在使用回收站视图,但我的问题是每张卡片都是屏幕宽度的 100% 而不是 70%。
这是每个项目的xml代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rowLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/scale_20dp">
<LinearLayout
android:id="@+id/button_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/currentYear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/paymentscreengrey"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="35dp"
android:paddingTop="@dimen/scale_50dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/scale_20dp"
android:text="**** **** **** 5432"
android:textColor="@color/white"
android:textSize="@dimen/scale_20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2345"
android:textColor="@color/white"
android:textSize="@dimen/scale_16dp" />
原文由 Adam Katz 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果您希望第一项左对齐(即,重现屏幕截图中的内容),子类
LinearLayoutManager
并覆盖三个generate*LayoutParams
方法。这是我的做法: https ://gist.github.com/bolot/6f1838d29d5b8a87b5fcadbeb53fb6f0。该解决方案基于/受跨越(即,将所有项目适合屏幕)线性布局管理器 https://gist.github.com/heinrichreimer/39f9d2f9023a184d96f8 启发。
顺便说一句,如果您只想向左和向右显示项目,而当前项目居中,则可以向回收站视图添加填充并将
clipToPadding
设置为false
.在这种情况下,您甚至不需要自定义布局管理器。