2010-08-06 5 views
52

दो लाइनरलेआउट के साथ मेरे ऐप के लिए एक स्क्रीन को विभाजित करना चाहते हैं। दो बराबर हिस्सों में सटीक विभाजन करने के लिए मुझे किन पैरामीटर का उपयोग करना चाहिए - शीर्ष पर पहले रैखिक लयआउट और दूसरा वाला इसके नीचे है।स्क्रीन को दो बराबर रैखिक लयआउट के साथ कैसे विभाजित करें?

+0

उपयोग वजन = प्रत्येक लेआउट – Sephy

+2

दोनों लेआउट के वजन "एक ही" होना चाहिए के लिए 0.5, नहीं है एक अंश – Siddharth

उत्तर

105

उपयोग वजन पैरामीटर, मोटे तौर पर लेआउट इस तरह दिखेगा:

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

<LinearLayout 
    android:layout_weight="1" 
    android:layout_height="fill_parent" 
    android:layout_width="0dp"/> 

<LinearLayout 
    android:layout_weight="1" 
    android:layout_height="fill_parent" 
    android:layout_width="0dp"/> 

</LinearLayout> 
+0

आप 3 'LinearLayout' की वर्तनी गलत नहीं किया जा जरूरत है। – Doomsknight

+0

@Doomsknight thx, तय! –

+2

लेआउट_वेट विशेषता का उपयोग करने के बारे में इस ट्यूटोरियल पर एक नज़र डालें http://www.chess-ix.com/2012/01/17/the-use-of-layout_weight-with-android-layouts/ –

11

बस इसे बाहर डाल:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FF0000" 
    android:weightSum="4" 
    android:padding="5dp"> <!-- to show what the parent is --> 
    <LinearLayout 
     android:background="#0000FF" 
     android:layout_height="0dp" 
     android:layout_width="match_parent" 
     android:layout_weight="2" /> 
    <LinearLayout 
     android:background="#00FF00" 
     android:layout_height="0dp" 
     android:layout_width="match_parent" 
     android:layout_weight="1" /> 
</LinearLayout> 
35

मैं 4-5 साल लेकिन सर्वोत्तम प्रथाओं क्या करने के बाद इस प्रश्न का उत्तर देते layout_ के उपयोग के रूप में इस सही दृष्टिकोण

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"> 

    <LinearLayout 
     android:id="@+id/firstLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_toLeftOf="@+id/secondView" 
     android:orientation="vertical"></LinearLayout> 

    <View 
     android:id="@+id/secondView" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_centerHorizontal="true" /> 

    <LinearLayout 
     android:id="@+id/thirdLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_toRightOf="@+id/secondView" 
     android:orientation="vertical"></LinearLayout> 
</RelativeLayout> 

नीचे के रूप में यह वह जगह है यूआई ऑपरेशंस के लिए वजन हमेशा भारी होता है। समान रूप से LinearLayout का उपयोग कर विभाजन लेआउट अच्छा अभ्यास

+0

वास्तव में बहुत अच्छा जवाब :) – Arlind

+0

एक आकर्षक की तरह काम करता है। कला उत्तर की अच्छी स्थिति – MPhil

+0

यह सही उत्तर होगा। –

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

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