2011-01-13 13 views
9

मैं एक लेआउट घटकों की ऊंचाई को एक और घटक के रूप में कैसे सेट कर सकता हूं: उदाहरण: क्या मैं एंड्रॉइड सेट कर सकता हूं: layout_height = "@ + id/info_box.height" या ऐसा कुछ करें?किसी अन्य घटक की एक ही ऊंचाई पर एक लेआउट घटक की ऊंचाई कैसे सेट करें?

मैं imageView की ऊंचाई मेरी LinearLayout

ImageView android:id="@+id/border" 
    android:src="@drawable/frame" 
android:layout_below="@+id/title" 
android:layout_width="fill_parent" 
android:layout_height="????"  
android:scaleType="fitXY" 
android:drawingCacheQuality="auto" 
/> 

<LinearLayout 
android:id="@+id/info_box" 
android:orientation="vertical" 
android:layout_below="@+id/title" 
android:background="@layout/my_bg" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
> 
... other stuff . . 
</LinearLayout> 
+0

उम्म। आप अपने रैखिक लेआउट में अपनी कल्पना क्यों नहीं डालते हैं और ऊंचाई को fill_parent के रूप में सेट करते हैं? – Falmarri

+0

@ फाल्मररी: यदि उसकी छवि दृश्य और लीनियरलाइट क्षैतिज लीनियरलाइट (निर्दिष्ट नहीं) के भीतर हैं, तो इसका कोई परिणाम नहीं होगा। साथ ही, क्या आपके पास बच्चे के लिए fill_parent और माता-पिता के लिए wrap_content हो सकता है? यह लगभग विरोधाभासी लगता है। – kcoppock

+0

अधिक जानकारी की आवश्यकता है। आपकी ImageView और LinerLayout रूट व्यू समूह क्या है? आप अपने लेआउट के साथ क्या हासिल करना चाहते हैं? –

उत्तर

4

प्राप्त करने के लिए इस दो दृश्य एक ही कंटेनर का हिस्सा बनने के लिए एक ही रास्ता है से मेल करना चाहते हैं। एक LinearLayout या RelativeLayout आमतौर पर इसके लिए उपयुक्त हैं। आप इसे कोड के माध्यम से भी प्राप्त कर सकते हैं।

+0

यदि आप एक ही कंटेनर का हिस्सा थे तो आप इसे कैसे करेंगे? मुझे लगता है कि वह ImageView पैमाने को LinearLayout की ऊंचाई पर बनाना चाहता है। –

+0

कभी नहीं, मुझे यह मिला। Imageview पर: scaletype = "centercrop", layout_height = "fill_parent", और layout_width = "fill_parent"। चाबी? scaletype = "centercrop" लेआउट संपादक पर काम नहीं करता है। –

1

आप android:layout_weight उपयोग कर सकते हैं।

उन्मुखीकरण के साथ एक ही LinearLayout में अपने दो दृश्य (सीमा और info_box) fill_parent और एक ही मूल्य layout_weight साथ रखो = verticale।

इस तकनीक, सीमा और info_box साथ

एक ही ऊंचाई होगा।

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

    <ImageView 
     android:id="@+id/border" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/title" 
     android:layout_weight="2" 
     android:drawingCacheQuality="auto" 
     android:scaleType="fitXY" 
     android:src="@drawable/frame" /> 

    <LinearLayout 
     android:id="@+id/info_box" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/title" 
     android:layout_weight="2" 
     android:background="@layout/my_bg" 
     android:orientation="vertical" > 

     ... other stuff . . 

    </LinearLayout> 

</LinearLayout> 
+1

वह fill_parent के साथ सभी विचार नहीं चाहता है। वह चाहता है कि कोई wrap_content हो, और दूसरा पहले के रूप में उच्च हो। – Danail

+0

वह पहले लीनियरलाइट की चौड़ाई और ऊंचाई बदल सकता है और वह इच्छित आकार चुन सकता है। लेकिन ImageView और दूसरा LinearLayout हमेशा एक ही ऊंचाई (या चौड़ाई) होगा, क्योंकि उनके पास समान लेआउट_वेट है .. – fingerup

+0

प्रभावी रूप से, wrap_content के साथ layout_weight संभव नहीं है ... – fingerup

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