ConstraintLayout作为RecyclerView项 [英] ConstraintLayout as RecyclerView Items
问题描述
我将ConstraintLayout
用作RecyclerView
项目.但是现在在真实计算机上显示了一些问题,预览中的问题不一样了
I use ConstraintLayout
as RecyclerView
item. But now there are some problems that are displayed on the real machine and in the preview is not the same
recyclerView项的布局如下:
The recyclerView item layout as follow:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/foreground_item_undo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="horizontal"
app:layout_constraintWidth_default="spread">
<com.lsl.wordhelper.view.RoundBgTextView
android:id="@+id/tv_item_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="8dp"
android:gravity="center"
android:padding="4dp"
android:text="G"
android:textColor="@android:color/white"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_item_explain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="释义:"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="@id/tv_item_original"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_item_original"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="Good"
android:textColor="@android:color/black"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@id/tv_item_explain"
app:layout_constraintLeft_toRightOf="@id/tv_item_icon"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_item_translate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="很好"
android:textColor="@android:color/black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="@id/tv_item_original"
app:layout_constraintTop_toBottomOf="@id/tv_item_explain" />
<TextView
android:id="@+id/tv_item_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:gravity="right"
android:text="2018/01/19"
android:textColor="@color/text_color_date"
app:layout_constraintBottom_toBottomOf="@id/tv_item_original"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
在Android Studio预览中.
In Android Studio preview .
但是在电话上
But on the phone
出什么问题了?
推荐答案
在您的代码中:
layout_marginStart
和layout_constraintLeft_toLeftOf
不相同,应使用
layout_marginStart
和layout_constraintStart_toStartOf
或layout_margintLeft
和layout_constraintLeft_toLeftOf
保持相同.向左离开,开始的时间有些不同.
如果您想将constraintlayout作为recyclerview看到更多.
https://developer.android.google.cn/reference/android/support/constraint/ConstraintLayout.html .
in you code:
layout_marginStart
andlayout_constraintLeft_toLeftOf
didn't same ,you should use
layout_marginStart
andlayout_constraintStart_toStartOf
or layout_margintLeft
andlayout_constraintLeft_toLeftOf
,keep same. left and start is diffent in some time.
see that get more if you want to make constraintlayout as recyclerview.
https://developer.android.google.cn/reference/android/support/constraint/ConstraintLayout.html.
这篇关于ConstraintLayout作为RecyclerView项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!