2017-07-13 9 views
6

मैं ConstraintLayout उपयोग कर रहा हूँ मैं कहाँ दिखाएगाConstraintLayout, जब बाधा निर्भर दृश्य समाप्त हो जाता, लेआउट दृश्य व्यवहार करते हैं निराले ढंग से

नीचे के रूप में

enter image description here

मैं छिपाने के लिए First (चला उपयोग करते हुए) चाहते हैं, और जो दृश्य मैं कहाँ ElasticBody रूप में अच्छी तरह मूल First दृश्य स्थान का उपयोग करने के लिए अधिक विस्तृत होंगी जैसा कि नीचे (होने की उम्मीद।

enter image description here

हालांकि, whe n मैं वास्तविक सेट First से gone पर, मेरा विचार नीचे जैसा दिखता है (एंड्रॉइड स्टूडियो डिज़ाइन व्यू के रूप में सभी छवि)। मेरा Elastic Body भी गायब है, और ऊंचाई अजीब तरह से फैली हुई है। नीचे

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="16dp"> 

    <TextView 
     android:id="@+id/txt_first" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#0ff" 
     android:text="First" 
     android:visibility="gone" 
     android:textSize="26sp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toStartOf="@+id/txt_body" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <TextView 
     android:id="@+id/txt_body" 
     android:layout_width="0dp" 
     android:background="#f0f" 
     android:layout_height="wrap_content" 
     android:text="Elastic Body" 
     android:textSize="26sp" 

     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toStartOf="@+id/txt_tail" 
     app:layout_constraintStart_toEndOf="@+id/txt_first" 
     app:layout_constraintTop_toBTopOf="parent" /> 

    <TextView 
     android:id="@+id/txt_tail" 
     android:background="#ff0" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Tail" 
     android:textSize="26sp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toEndOf="@+id/txt_body" 
     app:layout_constraintTop_toTopOf="parent" /> 

</android.support.constraint.ConstraintLayout> 

रूप

enter image description here

मेरे लेआउट कोड (ध्यान दें, यदि आप gone निकालने के लिए, आप पहली छवि को देखने के मिल जाएगा)। ऐसा क्यों है? मैं इसे कैसे ठीक कर सकता हूं, जब मेरा First चला गया है, तो क्या मैं Elastic Body सही तरीके से फैल सकता हूं?

पी/एस: मुझे पता है कि इसे रैखिकलायआउट और रिलेटिव लेआउट में कैसे करना है ... लेकिन आश्चर्य है कि यह कॉन्स्ट्रेनटआउट पर एक सीमा है या नहीं?

उत्तर

1

See Output :

कोशिश के बाद।

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="16dp"> 

    <TextView 
     android:id="@+id/txt_first" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#0ff" 
     android:text="First" 
     android:textSize="26sp" 
     android:visibility="gone" 
     app:layout_constraintEnd_toStartOf="@+id/txt_body" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" /> 

    <TextView 
     android:id="@+id/txt_body" 
     android:layout_width="0dp" 
     android:background="#f0f" 
     android:layout_height="wrap_content" 
     android:text="Elastic Body" 
     android:textSize="26sp" 
     app:layout_constraintRight_toLeftOf="@+id/txt_tail" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintLeft_toRightOf="@+id/txt_first" 
     /> 

    <TextView 
     android:id="@+id/txt_tail" 
     android:background="#ff0" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Tail" 
     android:textSize="26sp" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintRight_toRightOf="parent" /> 

</android.support.constraint.ConstraintLayout> 
+0

धन्यवाद। दिलचस्प, 'ऐप को हटा रहा है: layout_constraintStart_toEndOf =" पूंछ 'से @ @ id/txt_body "' मदद करता है। अपने उत्तर को ऊपर उठाओ। क्या आप तर्क को आगे बढ़ा सकते हैं? धन्यवाद! (सुनिश्चित नहीं है कि कौन मतदान नहीं करता है, उन्हें कम से कम एक कारण देना चाहिए ...) – Elye

+0

थोड़ी देर सोचने के बाद, मुझे लगता है कि मैं तर्क समझता हूं। मैं तुम्हारा उत्तर के रूप में टिक रहा हूँ। धन्यवाद! (अगर आपको लगता है कि दूसरों की मदद करता है तो मेरे प्रश्न को ऊपर उठाएं) – Elye

+0

कृपया मुझे वोट देने का कारण दें। –

2

एक और बात आप ConstraintLayout में Visibility.GONE के लिए उपयोग कर सकते हैं। आप इसके लिए Barriers का उपयोग कर सकते हैं।

अगर आप Barriers के बारे में जानकारी नहीं है तो यह जाँच कृपया: Barriers

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