【问题标题】:How to constrain an image to a guideline : Android constrained layout如何将图像约束到准则:Android 约束布局
【发布时间】: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


【解决方案1】:

如果您想支持多种屏幕尺寸,那么我认为您必须以编程方式做到这一点。

【讨论】:

  • 如何以编程方式实现这一点
猜你喜欢
  • 1970-01-01
  • 2019-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-12
  • 2022-11-02
  • 2017-11-05
  • 2023-04-07
相关资源
最近更新 更多