【发布时间】:2018-03-23 04:03:17
【问题描述】:
我的要求是放置图像的方式是图像的一半在水平线上方,另一半在水平线下方(正好一半)。我试过了
app:layout_constraintBottom_toBottomOf="@id/guideline"
app:layout_constraintTop_toTopOf="@id/guideline"
它在某些设备上正常工作。 我的要求是这样的
但在某些设备上,它不会分成两半。但仍然满足约束
我尝试了垂直偏差和垂直重量,但仍然无法解决这个问题我该如何解决?
我觉得这些约束还是满足的
app:layout_constraintBottom_toBottomOf="@id/guideline"
app:layout_constraintTop_toTopOf="@id/guideline"
有什么有效的方法可以满足我的要求吗?
我的 XML 的一部分
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.3" />
<com.cloud.appsteam.profile.HexagonMaskView
android:id="@+id/iv_profile_image"
android:layout_width="@dimen/profile_img_width"
android:layout_height="@dimen/profile_img_height"
android:scaleType="centerCrop"
android:src="@drawable/neymar_dp"
app:layout_constraintBottom_toBottomOf="@id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/guideline" />
【问题讨论】:
-
您是否使用百分比定义了您的指南?
-
请发布您的布局代码
-
我认为您应该发布您的 xml 代码,以便我们更清楚您的问题,我们可以观察实际问题。
-
你有没有试过 LayoutInspector 来找出问题developer.android.com/studio/debug/layout-inspector.html
-
您只需要顶部和底部边距——这里不需要垂直偏差。如果它适用于某些设备而不适用于其他设备,那就是另一个问题。您使用的是哪个版本的 ConstraintLayout?
标签: android android-layout android-imageview android-constraintlayout