Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 对自定义视图使用约束布局_Android_Xml_Android Layout_Android Constraintlayout - Fatal编程技术网

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

Android 对自定义视图使用约束布局,android,xml,android-layout,android-constraintlayout,Android,Xml,Android Layout,Android Constraintlayout,我正在使用布局编辑器中的拖放功能尝试将4个图像按钮对齐成风筝形状。这是我正在尝试实现的布局,目前使用的是ImageButton,但稍后我将更改为圆形图像视图以适应布局。 谁能帮我做到这一点。请在下面找到我的XML: <android.support.constraint.ConstraintLayout android:id="@+id/ongoing_call_layout" android:layout_width="match_parent" android

我正在使用布局编辑器中的拖放功能尝试将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>


但也许你真正的问题是ConstraintLayout不是你的根元素,你应该设置一个固定的高度而不是android:layout\u height=“wrap\u content”

你可以使用垂直偏差而不是边距。deadfish你是对的,但正如你所看到的,他在父容器中使用的是layout\u heigt=“wrap\u content”,所以垂直偏差在这里不起作用。标记为正确答案,因为它是最接近问题的答案。看到
ConstraintLayout
使用起来很麻烦,我继续使用了一个带有三行三列的
TableLayout