2017-06-06 136 views
1

XML:邊距不工作的滾動型

<?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> 

的ImageView的可見性設置爲走了,當用戶將圖像的可見度變爲可見和ImageView的推動下提交按鈕。

但是,結果是不可取的,它使提交按鈕錨佈局的最底部。正如你可以看到: enter image description here

我的問題是,我怎麼能使這個佈局尊重提交按鈕的底部邊距?

回答

0

添加layout_marginBottom其父(在這種情況下,ConstraintLayout)可能會奏效。

在我看來,所有這些約束屬性可能會搞砸了利潤率。對於這種佈局,我認爲你不需要ConstraintLayout。 A LinearLayout會做得很好。

+0

我切換到線性佈局,約束和線性佈局都無助於這種情況。我沒有將layout_marginBottom添加到線性和約束佈局。 – Rosenberg

+0

按鈕的'layout_marginBottom'屬性正在工作。按鈕下方的黑色空格是一個邊距(請注意,您的滾動視圖具有黑色背景)。你的問題在這裏可能是你的'ConstraintLayout'的高度。它的高度是0dp,並將變成其子女的身高。也許如果你把它放到'match_parent',你會得到你想要的綠色背景 –

0

我也面臨着同樣的問題,它是由包木窗與另一個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"> 


    <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> 

保證金問題只滾動型的根的孩子,你可以添加邊距內孩子造成的。