Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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 Constraintlayout - Fatal编程技术网

Android 页边距不适用于滚动视图

Android 页边距不适用于滚动视图,android,xml,android-constraintlayout,Android,Xml,Android Constraintlayout,XML: 我的问题是,如何使此布局与submit按钮的底部边距保持一致?将布局_marginBottom添加到其父级(在这种情况下,约束布局)可能会起作用 在我看来,所有这些约束属性都可能弄乱了边距。对于这种布局,我认为您不需要ConstraintLayout。一个LinearLayout就可以了。我也遇到了同样的问题,通过用另一个没有边距的LinearLayout包装子布局解决了这个问题。你的情况是 <?xml version="1.0" encoding="utf-8"?>

XML:



我的问题是,如何使此布局与submit按钮的底部边距保持一致?

布局_marginBottom
添加到其父级(在这种情况下,
约束布局
)可能会起作用


在我看来,所有这些约束属性都可能弄乱了边距。对于这种布局,我认为您不需要
ConstraintLayout
。一个
LinearLayout
就可以了。

我也遇到了同样的问题,通过用另一个没有边距的LinearLayout包装子布局解决了这个问题。你的情况是

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fancy="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBlack"
android:fillViewport="true"
android:orientation="vertical">

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:background="@color/colorNavigationKolBG"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical">

  <!-- FORM STUFF HERE, I CUT IT OUT -->

    <mehdi.sakout.fancybuttons.FancyButton
        android:id="@+id/btn_add_pic"
        android:layout_width="250dp"
        android:layout_height="40dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="7dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/descriptionForm"
        fancy:fb_borderColor="@color/colorNavigationKolBTN"
        fancy:fb_borderWidth="1dp"
        fancy:fb_defaultColor="@color/colorNavigationKolBTN"
        fancy:fb_focusColor="#3B5F6A"
        fancy:fb_fontIconResource="&#xf030;"
        fancy:fb_fontIconSize="20sp"
        fancy:fb_iconPosition="left"
        fancy:fb_radius="0dp"
        fancy:fb_text="Add Image"
        fancy:fb_textColor="#FFFFFF"
        fancy:fb_textSize="20sp" />

    <mehdi.sakout.fancybuttons.FancyButton
        android:id="@+id/btn_submit"
        android:layout_width="250dp"
        android:layout_height="60dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearImageLayout"
        fancy:fb_borderColor="@color/colorNavigationKolBTN"
        fancy:fb_borderWidth="1dp"
        fancy:fb_defaultColor="@color/colorNavigationKolBTN"
        fancy:fb_focusColor="#3B5F6A"
        fancy:fb_fontIconResource="&#xf00c;"
        fancy:fb_fontIconSize="20sp"
        fancy:fb_iconPosition="left"
        fancy:fb_radius="0dp"
        fancy:fb_text="Submit"
        fancy:fb_textColor="#FFFFFF"
        fancy:fb_textSize="20sp" />


    <LinearLayout
        android:id="@+id/linearImageLayout"
        android:layout_width="0dp"
        android:layout_height="150dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/border"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/btn_add_pic"
        fancy:srcCompat="@color/cardview_light_background">

        <ImageView
            android:id="@+id/imageForm"
            android:layout_width="match_parent"
            android:layout_height="150dp" />

    </LinearLayout>


</android.support.constraint.ConstraintLayout>


页边距问题仅对scrollview的根子级造成。您可以将页边距添加到内部子级。

将android:paddingBottom
添加到父级ConstraintLayout有效。

我切换到了线性布局,约束和线性布局在这种情况下都没有帮助。我确实在线性和约束布局中添加了layout_marginBottom。按钮的
layout_marginBottom
属性正在工作。按钮下方的黑色空间是边距(请注意,您的scrollview具有黑色背景)。这里的问题可能是您的
ConstraintLayout
的高度。它的高度是0dp,将变成它孩子的高度。也许如果你把它放到“匹配父项”中,你会得到你想要的绿色背景
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fancy="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBlack"
android:fillViewport="true"
android:orientation="vertical">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:background="@color/colorNavigationKolBG"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical">

  <!-- FORM STUFF HERE, I CUT IT OUT -->

    <mehdi.sakout.fancybuttons.FancyButton
        android:id="@+id/btn_add_pic"
        android:layout_width="250dp"
        android:layout_height="40dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="7dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/descriptionForm"
        fancy:fb_borderColor="@color/colorNavigationKolBTN"
        fancy:fb_borderWidth="1dp"
        fancy:fb_defaultColor="@color/colorNavigationKolBTN"
        fancy:fb_focusColor="#3B5F6A"
        fancy:fb_fontIconResource="&#xf030;"
        fancy:fb_fontIconSize="20sp"
        fancy:fb_iconPosition="left"
        fancy:fb_radius="0dp"
        fancy:fb_text="Add Image"
        fancy:fb_textColor="#FFFFFF"
        fancy:fb_textSize="20sp" />

    <mehdi.sakout.fancybuttons.FancyButton
        android:id="@+id/btn_submit"
        android:layout_width="250dp"
        android:layout_height="60dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearImageLayout"
        fancy:fb_borderColor="@color/colorNavigationKolBTN"
        fancy:fb_borderWidth="1dp"
        fancy:fb_defaultColor="@color/colorNavigationKolBTN"
        fancy:fb_focusColor="#3B5F6A"
        fancy:fb_fontIconResource="&#xf00c;"
        fancy:fb_fontIconSize="20sp"
        fancy:fb_iconPosition="left"
        fancy:fb_radius="0dp"
        fancy:fb_text="Submit"
        fancy:fb_textColor="#FFFFFF"
        fancy:fb_textSize="20sp" />


    <LinearLayout
        android:id="@+id/linearImageLayout"
        android:layout_width="0dp"
        android:layout_height="150dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/border"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/btn_add_pic"
        fancy:srcCompat="@color/cardview_light_background">

        <ImageView
            android:id="@+id/imageForm"
            android:layout_width="match_parent"
            android:layout_height="150dp" />

    </LinearLayout>


</android.support.constraint.ConstraintLayout>

    </LinearLayout>

</ScrollView>