2011-09-13 22 views
22

संलग्न छवि में, मैं बटन छवि की ऊंचाई मैच के लिए की स्तंभ चाहते हैं, लेकिन मैं भी वहाँ चाहते बटन के स्तंभ के लिए एक न्यूनतम ऊंचाई होने के लिए।minHeight कुछ भी करता है?

यह सही ढंग से छवि की ऊंचाई से मेल खाता है, लेकिन minHeight सम्मान नहीं करता है, और बटन नीचे smoosh होगा।

मैं बटन के स्तंभ के लिए इन गुणों की स्थापना कर रहा हूँ:

<LinearLayout 
    ... 
    android:layout_alignTop="@+id/image" 
    android:layout_alignBottom="@+id/image" 
    android:minHeight="150dp" 
    > 

enter image description here

उत्तर

38

मैं अपने सभी सटीक आवश्यकताओं को पता नहीं है, लेकिन यह काफी है जैसे आप एक और परत के साथ इस हल कर सकते हैं लगता है आपके आरेख में बाहरी लेआउट पर minHeight सेट करें और फिर अंदर fill_parent/match_parent सेट करें। हो सकता है कि कुछ इस तरह:

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:minHeight="150dp"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_height="fill_parent" 
     android:layout_width="wrap_content"> 
    </LinearLayout> 
    <ImageView /> 
</LinearLayout> 
+2

लेकिन याद रखें: यदि आप कई लेआउट के लिए उपयोग अपने अनुप्रयोग स्टार्टअप पर सुस्त हो सकता है। ऐसा लगता है कि लेआउट को स्टार्टअप पर बहुत सारी मेमोरी की आवश्यकता होती है जो कचरा संग्रह को आपके ऐप को धीमा कर सकती है जब तक स्टार्टअप के लिए आवश्यक स्मृति को फिर से मुक्त नहीं किया जाता है। और हाँ, मुझे वह समस्या है और वर्तमान में मैं इसके बजाय RelativLayout पर स्विच करने का प्रयास करता हूं। – Martin

6

ट्रिकी सवाल है क्योंकि यह TextView.setMinHeight कॉल - लेकिन फिर आप एक TextView उपयोग नहीं कर रहे।

तो आम तौर पर android:minHeight वास्तव में कुछ नहीं बल्कि अपने विशेष मामले में क्या करता है।

+5

यह पूछे गए मूल प्रश्न का एक अच्छा जवाब था। यह शायद उपयोगकर्ता को अपना अंतिम लक्ष्य प्राप्त करने में मदद नहीं करता है, लेकिन फिर भी मुझे यह दिलचस्प लगता है। – jwir3

+1

यह पूरी तरह से गलत है। विचारों के लिए सामान्य रूप से minHeight एक वैध विशेषता है। इसका प्रोग्रामेट समतुल्य https://developer.android.com/reference/android/view/View.html#setMinimumHeight(int) –

+1

@ डेविड लियू कि विशेषता एक्सएमएल में मान्य है इसका मतलब यह नहीं है कि यह संग्रहीत है राय। और यहां तक ​​कि जब विशेषता को ध्यान में रखते संग्रहीत किया जाता है यह है कि इसका मतलब यह नहीं वास्तव में सक्रिय लेआउट प्रबंधक द्वारा प्रयोग किया जाता है है। और इसे और भी मजेदार बनाने के लिए: एक 'TextView.setMinHeight' और' View.setMinimumHeight' – Martin

0

हालांकि मेरे दूसरे सवाल का जवाब अभी भी मान्य है, आजकल हम ConstraintLayout के लाभ के लिए है। मुझे यकीन है कि मूल पोस्टर इस समस्या से पहले लंबे समय से प्राप्त हुआ है, लेकिन भविष्य के उपयोगकर्ताओं के लिए: आप ViewGroup एस की अतिरिक्त परत के बिना एक ही परिणाम प्राप्त कर सकते हैं। कुछ इस तरह: बड़े चित्र को संभालने के लिए

app:layout_constrainedWidth="true" 
ImageView के लिए

, लेकिन मैं इसे परीक्षण नहीं किया:

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

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:text="Button1" 
     app:layout_constraintBottom_toTopOf="@+id/button2" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:text="Button2" 
     app:layout_constraintBottom_toTopOf="@+id/button3" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/button1" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:text="Button3" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/button2" /> 

    <android.support.constraint.Barrier 
     android:id="@+id/barrier" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:barrierDirection="end" 
     app:constraint_referenced_ids="button1,button2,button3" /> 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="@id/barrier" 
     app:layout_constraintTop_toTopOf="parent" /> 
</android.support.constraint.ConstraintLayout> 

संभवत: आप की तरह कुछ पड़ सकता है।

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