2010-05-25 8 views
10

मेरे पास मेरे डिस्प्ले के शीर्ष पर एक छवि दृश्य है जो निम्न जैसा दिखता है:मैं ImageView के लिए गतिशील ऊंचाई कैसे निर्दिष्ट कर सकता हूं?

╔══════════════════════════════════════════════╗ 
║ ImageView ╔══════════════╗    ║ 
║    ║    ║    ║ 
║    ║ Actual image ║    ║ 
║    ║    ║    ║ 
║    ║    ║    ║ 
║    ║    ║    ║ 
║    ╚══════════════╝    ║ 
╚══════════════════════════════════════════════╝ 

इसके नीचे, मेरे पास बटन और टेक्स्ट व्यूज़ की एक श्रृंखला है ..

मैं छवि दृश्य की ऊंचाई को गतिशील रूप से बढ़ाना चाहता हूं स्क्रीन की अधिकतम ऊंचाई के आधार पर। मैं स्क्रीन के किनारे के नीचे वाले बटन वाले लेआउट को संरेखित कर रहा हूं, और मैं उपरोक्त छवि दृश्य द्वारा उठाई गई शेष स्क्रीन चाहूंगा।

इसके अलावा, चूंकि ImageView में एक केंद्रित छवि है, इसलिए मैं छवि ऊंचाई और नीचे दिए गए बटन प्रदर्शित करने के लिए स्क्रीन बहुत छोटा होने पर न्यूनतम ऊंचाई और स्क्रॉलबार भी सेट करना चाहूंगा।

धन्यवाद!

क्या यह संभव है?

+13

एएससीआई विज़ुअलाइज़ेशन उत्कृष्टता के लिए +1। – womp

उत्तर

5

यदि आप android:layout_width का उपयोग करते हैं तो पहला भाग बहुत आसान होना चाहिए। यदि आप केवल imageView (या इसके कंटेनर) के लिए लेआउट_विड्थ सेट करते हैं, तो यह जितना संभव हो उतना मूल लेआउट ले लेगा। उदाहरण के लिए, यदि आप एक लेआउट जहां एक imageView स्क्रीन के पूरे आराम ले लिया था, यदि आप ऐसा करते हैं:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:src="@drawable/icon" 
     android:scaleType="fitCenter" android:layout_weight="1" /> 
    <LinearLayout android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <!-- Put whatever you want in here --> 
    </LinearLayout> 
</LinearLayout> 

इस उदाहरण में मैं पूरे स्क्रीन शुरू करने के लिए छवि खींच रही है, लेकिन आप "स्क्रीन के लिए छवि बहुत बड़ी है और मुझे स्क्रॉलिंग की आवश्यकता है" की समस्या भी प्रस्तुत करते हैं? उस स्थिति में, आपको केवल लेआउट में स्क्रॉलव्यू जोड़ने की ज़रूरत है। यदि छवि खड़ी बहुत लंबा है, स्क्रीन स्वचालित रूप से स्क्रॉल करेगा:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:fillViewport="true"> 
    <LinearLayout android:orientation="vertical" 
     android:layout_width="fill_parent" android:layout_height="fill_parent"> 
     <ImageView android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:src="@drawable/huge" 
      android:scaleType="fitCenter" android:layout_weight="1" /> 
     <LinearLayout android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
      <!-- Insert your content here --> 
     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 

नोट करने के लिए एक महत्वपूर्ण बात: अगर आप scrollview पर सत्य पर android:fillViewport सेट नहीं है, ImageViews कि बहुत छोटा भरने नहीं होगा पूरी स्क्रीन

0

पूरी तरह से वह उत्तर नहीं जिसे आप ढूंढ रहे हैं लेकिन यह निश्चित रूप से आपकी कक्षा के माध्यम से scrollateloutout scrollview और गतिशील कोडिंग के मिश्रण के माध्यम से संभव है। इस समय एक प्रोग्रामिंग कंप्यूटर के पास नहीं, लेकिन अस्पष्ट उत्तर "संभव है? हाँ!" :)

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

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