Liu*_*ong 5 android android-recyclerview
我ConstraintLayout用作RecyclerView项目.但是现在有一些问题显示在真机上并且在预览中不一样
recyclerView项目布局如下:
<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>
Run Code Online (Sandbox Code Playgroud)
在Android Studio预览中.

但是在电话里

有什么问题?
更新适配器的 oncreateView :
//view is what we return from onCreateViewHolder
view.apply {
this.layoutParams = RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
}
Run Code Online (Sandbox Code Playgroud)
这总是有效的。
che*_*hen -6
在你的代码中:
layout_marginStartandlayout_constraintLeft_toLeftOf不一样,你应该使用
layout_marginStartandlayout_constraintStart_toStartOf或layout_margintLeftand layout_constraintLeft_toLeftOf,保持相同。左和开始在某些时候是不同的。如果你想将constraintlayout设置为recyclerview,请参阅获取更多内容。
https://developer.android.google.cn/reference/android/support/constraint/ConstraintLayout.html。
| 归档时间: |
|
| 查看次数: |
4993 次 |
| 最近记录: |