【发布时间】:2017-10-20 20:33:03
【问题描述】:
我对新的约束布局有一些问题。 我正在使用 RecyclerView,该项目的布局基于一个约束布局,其中包含 2 个 TextViews 和 1 个 ImageView。 在 Android Studio 的设计视图中,一切看起来都很好,但在实际设备(带有 Lineage OS 的 S5)上,ImageView 在某些活动中改变了它的位置。 如果我向下滚动,这些项目就是它们应该的样子,当向上滚动时,一切都会恢复正常。 我提到我正在使用 Recycler 视图为 3 个片段重用相同的布局文件。 这是 1 个列表项的布局。
<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/cont_item_root"
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="@drawable/bottom_border"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:paddingLeft="16dp">
<TextView
android:id="@+id/lbl_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="0dp"
android:gravity="center"
android:text="wqewqwewqeqw"
android:textColor="@android:color/black"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@+id/lbl_item_desc"
app:layout_constraintHorizontal_bias="0.008"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="@+id/lbl_item_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="14sp"
android:text="weqweweqweweqeweqwe"
android:layout_marginRight="0dp"
android:layout_marginEnd="72dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="@+id/lbl_item_title"
android:layout_marginBottom="7dp"
app:layout_constraintRight_toRightOf="@+id/lbl_item_title"
app:layout_constraintHorizontal_bias="0.0"/>
<ImageView
android:id="@+id/lbl_item_save"
android:contentDescription="@string/bookmarked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_star_border_black_24dp"
android:layout_marginEnd="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginRight="24dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@+id/lbl_item_desc"
android:layout_marginLeft="8dp"
app:layout_constraintHorizontal_bias="1.0" />
在手机上,在第一个片段中,一切都很好,无论我按什么顺序打开它。但是如果我打开第二个或第三个片段,事情就会变得一团糟。
有人知道什么会影响 ImageView(星星)移动吗?
谢谢!
【问题讨论】:
-
我也面临着同样尴尬的局面。当我向下滚动时,一切正常。但是当我向上滚动正确定位的图像视图时,它会失去它的约束。我将约束布局更改为线性布局,但错误仍然存在。
标签: android android-fragments layout android-recyclerview android-constraintlayout