对自定义视图使用约束布局

甜心阿南

我正在使用布局编辑器中的拖放功能来尝试将 4 个图像按钮对齐成风筝形状。这是我正在尝试实现的布局,目前正在使用,ImageButton但稍后我将更改为圆形图像视图以适应布局。布局目标的屏幕抓取

任何人都可以帮助我实现这一目标。请在下面找到我的 XML:

<android.support.constraint.ConstraintLayout
    android:id="@+id/ongoing_call_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/activity_padding"
    android:layout_below="@id/contact_number_tv"
    android:layout_above="@id/calculator_layout">

    <ImageButton
        android:id="@+id/home_imgBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="120dp"
        android:src="@android:drawable/btn_star"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/not_billable_imgBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="104dp"
        android:src="@android:drawable/btn_star"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/billable_imgBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/btn_star"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toEndOf="@+id/not_billable_imgBtn"
        tools:layout_editor_absoluteY="105dp" />


    <ImageButton
        android:id="@+id/decide_later_imgBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="120dp"
        android:src="@android:drawable/btn_star"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />


</android.support.constraint.ConstraintLayout>
阿德里安德龙

试试这个伙伴,并进行自己的调整。

<android.support.constraint.ConstraintLayout 
    android:id="@+id/ongoing_call_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/activity_padding"
    android:layout_below="@id/contact_number_tv"
    android:layout_above="@id/calculator_layout">

    <ImageButton
        android:id="@+id/home_imgBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:src="@android:drawable/btn_star"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.32"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/not_billable_imgBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="24dp"
        android:src="@android:drawable/btn_star"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/billable_imgBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:src="@android:drawable/btn_star"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.66"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/decide_later_imgBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="60dp"
        android:layout_marginBottom="24dp"
        android:src="@android:drawable/btn_star"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/not_billable_imgBtn" />

 </android.support.constraint.ConstraintLayout>

查看示例图像

但也许你真正的问题是 constrainLayout 不是你的根元素,你应该设置一个固定的高度而不是 android:layout_height="wrap_content"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

自定义视图不遵守约束布局中的约束

约束布局自定义页脚

Android-如何布局和使用自定义视图?

将自定义视图用作RecyclerView中的项目-约束布局无法处理约束宽度匹配的子项

android:自定义视图布局包装

创建自定义集合视图布局

自定义视图扩展相对布局

在布局中重复自定义视图

自定义视图弄乱了布局

在自定义警报对话框上使用约束布局

检查使用自定义函数的约束

如何使用isInEditMode()在编辑器中使用自定义视图查看布局

使用自定义属性在<include>标记中使用的布局内编辑视图(TextView / ImageView)

iOS:自定义表格视图单元中的约束

在已被自定义视图替换的NSMenuItem上应用约束

使用自定义布局解析

使用 flexbox 自定义布局

如何管理与布局使用ConstraintLayout自定义视图的宽度是多少?

如何在自定义对话框布局中使用视图绑定?

使用自定义维度在初始化时布局单元格子视图

使用自定义视图填充非常长的线性布局,速度非常慢

使用自定义列表视图适配器和不同布局的结果不正确

使用情节提要板实现自定义视图布局

如何使用在 Android 自定义视图中设置的属性调整膨胀布局的大小?

在Rails上使用自定义布局无法访问视图上的实例变量

自定义布局未使用constraintLayout 在列表视图中居中

如何通过数据绑定使用自定义视图膨胀线性布局

在自定义视图构造函数中膨胀活动布局

如何为以下布局制作自定义视图?