【发布时间】:2021-03-15 05:02:53
【问题描述】:
我得到了以下布局,您也可以看到我的“查看更多”按钮与底部边缘线的垂直中心/中间完全对齐。
app:layout_constraintBottom_toBottomOf="@id/iv_content"
app:layout_constraintTop_toBottomOf="@id/iv_content"
现在,如果我想将“查看更多”按钮稍微向下推动大约 2% 的高度或 2dp,例如。
我试过 android:layout_marginTop="50dp" 没有什么不同
app:layout_constraintVertical_bias="0.8" 也不例外。
除了老派方法之外,我还能做什么“约束解决方案”:
app:layout_constraintBottom_toBottomOf="parent"(申请btn_view_more)然后硬编码marginBottom并向上推
我知道这是解决方案之一,但我很想知道是否有任何我不知道的与约束相关的解决方案
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/iv_content"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginHorizontal="@dimen/_20sdp"
android:layout_marginVertical="@dimen/_50sdp"
android:background="@drawable/background_transparent_round_corner"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/iv_close"
android:layout_width="@dimen/_30sdp"
android:layout_height="@dimen/_30sdp"
android:background="@drawable/background_circle"
android:src="@drawable/ic_close"
app:layout_constraintBottom_toTopOf="@id/iv_content"
app:layout_constraintEnd_toEndOf="@id/iv_content"
app:layout_constraintStart_toEndOf="@id/iv_content"
app:layout_constraintTop_toTopOf="@id/iv_content" />
<air.com.my.companyname.util.font.InterRegularButton
android:id="@+id/btn_view_more"
style="@style/ButtonSolidBlue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/_40sdp"
android:layout_marginTop="50dp"
android:text="View More"
app:layout_constraintBottom_toBottomOf="@id/iv_content"
app:layout_constraintEnd_toEndOf="@id/iv_content"
app:layout_constraintStart_toStartOf="@id/iv_content"
app:layout_constraintTop_toBottomOf="@id/iv_content" />
</androidx.constraintlayout.widget.ConstraintLayout>
【问题讨论】:
-
有办法但不知道是不是你最终想要达到的。与其将“查看更多”按钮限制在图像视图的底部,不如将其限制在图像视图的顶部。这将使按钮以您的图像视图为中心。现在使用分数值大于 1 的垂直偏差,例如 '1.02' 等。
-
我试过这个,但似乎 , 1 或 1.02 是对底部的约束,或者我会说向下移动,我试过放 -0.2 ,但似乎不可能,偏差 0.0 将停留在顶部(
iv_content的底部) -
值大于 1 导致部分按钮移出屏幕
标签: android android-constraintlayout