10

marginTop के नीचे xml का उपयोग करके अनदेखा किया जा रहा है यदि दृश्य की दृश्यता जिसे मैं बाध्य कर रहा हूं।ConstraintLayout मार्जिन काम नहीं कर रहे

यह इस समय com.android.support.constraint:constraint-layout:1.0.0-beta4

उदाहरण पर नवीनतम लेआउट lib संस्करण के साथ होता है:

tvMessage और ivCommentImagevisible कर रहे हैं - llLeftActions और llRightActions पर 16dp ऊपरी हाशिया ठीक काम कर रहा है। यदि ivCommentImagegone है मार्जिन को अनदेखा किया जाता है।

<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

<android.support.constraint.ConstraintLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="16dp"> 

<!-- some more views here --> 

    <TextView 
     android:id="@+id/tvMessage" 
     style="@style/SocialFeed.Description" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="16dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginStart="16dp" 
     android:layout_marginTop="16dp" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/ivProfile" 
     app:layout_goneMarginTop="0dp" 
     tools:text="@string/lorem_ipsum_140chars"/> 

    <android.support.v7.widget.AppCompatImageView 
     android:id="@+id/ivCommentImage" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="16dp" 
     android:adjustViewBounds="true" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/tvMessage" 
     app:layout_goneMarginTop="0dp" 
     /> 

    <android.support.constraint.Guideline 
     android:id="@+id/gCenter" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     app:layout_constraintGuide_percent="0.5"/> 

    <LinearLayout 
     android:id="@+id/llLeftActions" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="16dp" 
     android:gravity="center_vertical|left" 
     android:orientation="horizontal" 
     app:layout_constraintLeft_toLeftOf="@+id/tvMessage" 
     app:layout_constraintRight_toLeftOf="@+id/gCenter" 
     app:layout_constraintTop_toBottomOf="@+id/ivCommentImage" 
     app:layout_goneMarginTop="0dp" 
     /> 

    <LinearLayout 
     android:id="@+id/llRightActions" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="16dp" 
     android:gravity="center_vertical|right" 
     android:orientation="horizontal" 
     app:layout_constraintLeft_toLeftOf="@+id/gCenter" 
     app:layout_constraintRight_toRightOf="@+id/tvMessage" 
     app:layout_constraintTop_toBottomOf="@+id/ivCommentImage" 
     app:layout_goneMarginTop="0dp"/> 


</android.support.constraint.ConstraintLayout> 

</android.support.v7.widget.CardView> 

उत्तर

6

यह पूरी तरह से अपेक्षानुसार काम कर रहा है - ध्यान दें कि आप @id/llLeftActions और @id/llRightActions पर layout_goneMarginTop="0dp" जोड़ा ...

जिसका मतलब है कि के रूप में चला गया जब विजेट वे ओर इशारा करते हैं (@id/ivCommentImage) चिह्नित है, मार्जिन जो शीर्ष कनेक्शन के लिए उपयोग किया जाएगा ... 0 डीपी, और 16 डीपी का मार्जिन नहीं होगा। यही वह गुण है जो यहां हैं! :)

जांच दस्तावेज़ visibility behavior पर और gone margin attributes

1
<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Available chats" 
    tools:layout_editor_absoluteX="1dp" 
    tools:layout_editor_absoluteY="1dp" /> 

<ListView 
    android:id="@+id/listChats" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    app:layout_constraintTop_toBottomOf="@+id/textView"/> 

अंतिम पंक्ति नोटिस कृपया, किनारों के आसपास की कमी जोड़ने बाधा काम में आता है।

आप स्टूडियो में डिज़ाइन व्यू का भी उपयोग कर सकते हैं, और ऑब्जेक्ट्स के बीच बाधाओं को खींच और छोड़ सकते हैं।

संबंधित मुद्दे