2012-09-06 14 views
6

मैं एंड्रॉइड में काफी नया हूं, इसलिए यह शायद एक बेवकूफ सवाल होगा, लेकिन यहां यह जाता है।एंड्रॉइड: स्क्रीन रिज़ॉल्यूशन के प्रतिशत में लेआउट ऊंचाई

मेरे पास गतिविधि का सापेक्ष समय है। इस लेआउट में मेरे पास स्क्रीन के नीचे एक और लेआउट है। कभी-कभी मैं इसे छुपाता हूं या इसे दृश्यमान करता हूं, यह महत्वपूर्ण नहीं है। क्या एक और लेआउट की ऊंचाई बनाना संभव है कि कुल स्क्रीन ऊंचाई का 27% कहें? विचार स्क्रीन पर इस लेआउट को छोड़कर, अन्य सामग्री को रखना है।

क्या किसी ने ऐसा कुछ करने की कोशिश की है?

+0

आप आप अपनी स्क्रीन के दो भागों चाहते कहने के लिए मतलब है? या क्या आपका मतलब है कि आप एक ऐसा दृश्य चाहते हैं जो दृश्यमान होने पर पूरे माता-पिता के निचले 27% को कवर करने वाले किसी अन्य दृश्य के अंदर बैठे? – brianestey

उत्तर

22

LinearLayoutandroid:layout_weight के माध्यम से इसे संभाल सकता है। उदाहरण के लिए, यहाँ तीन Button विगेट्स युक्त, 50%, 30%, और ऊंचाई का 20%, क्रमशः ले एक लेआउट है:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="50" 
     android:text="@string/fifty_percent"/> 

    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="30" 
     android:text="@string/thirty_percent"/> 

    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="20" 
     android:text="@string/twenty_percent"/> 

</LinearLayout> 

हालांकि, आप बस की घोषणा नहीं कर सकते हैं कि एक मनमाना बिंदु पर एक मनमाना विजेट आपकी लेआउट फ़ाइल में स्क्रीन आकार का मनमाना प्रतिशत लेना चाहिए। जावा में उस गणना को करने के लिए आपका स्वागत है और आवश्यकतानुसार अपने विजेट के LayoutParams को समायोजित करें।

+0

बिल्कुल सही समाधान –

1

आप इसे आजमा सकते हैं, अधिक जटिल लेकिन उपयोगी है। शीर्ष अपनी स्क्रीन के 73% और दूसरे जा रहा है 27% किया जा रहा है -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/parent_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" /> 

<LinearLayout 
    android:id="@+id/parent_of_bottom_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_alignParentBottom="true" > 

    <LinearLayout 
     android:id="@+id/content_view" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="27"> 

     //Add your content here 

    </LinearLayout> 
</LinearLayout> 

+0

क्या आप यह काम कर सकते हैं कि यह कैसे काम करता है और यह प्रश्न का उत्तर क्यों देता है? –

+0

आप एंड्रॉइड का उपयोग नहीं कर सकते हैं: लेआउट_वेट रिलेटिवलायआउट के अंदर, इसलिए मैंने एक रिश्तेदार लेआउट के अंदर अनुपात में वेग्नेट बनाने के लिए लीनियरलाइट का उपयोग किया, मुझे अपने कोड प्रोजेक्ट से समाधान मिला, इसलिए मैंने इसे साझा किया। – wSakly

+0

धन्यवाद, यह समस्या का एक दिलचस्प दृष्टिकोण है। –

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