【发布时间】:2021-09-29 14:00:10
【问题描述】:
我目前在回收站内使用卡片视图,尽管我努力了,但文本是左对齐的。
这是图书项目布局。
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:cardCornerRadius="4dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true"
app:cardBackgroundColor="@color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/bookTitleTextView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
这是回收站本身。
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/bookRecycler" />
这是当前的输出。 enter image description here
如您所见,文本未居中。
我尝试使用布局重力使文本居中,但不起作用。 我还尝试在文本视图上使用约束布局并使用约束将文本居中而没有任何运气。
android:layout_gravity = "center" 已经尝试过了。
任何关于我所忽略的建议都会很棒。 谢谢。
【问题讨论】:
标签: java android android-recyclerview center android-cardview