रैखिक लेआउट के बारे में जानने के लिए मैं this tutorial का अनुसरण कर रहा हूं।लिनियरलाइट विशेषता "लेआउट_वेट" क्यों करती है जो मुझे लगता है कि इसके विपरीत क्या करना चाहिए?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="red"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="green"
android:gravity="center_horizontal"
android:background="#00aa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="blue"
android:gravity="center_horizontal"
android:background="#0000aa"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="yellow"
android:gravity="center_horizontal"
android:background="#aaaa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="row one"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row two"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row three"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row four"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
कौन इस का उत्पादन:
मैं शीर्ष पर रंग सलाखों (लेआउट के पहले बच्चे) बनाने की कोशिश कर के साथ प्रयोग किया गया था खड़ी दो बार के रूप यहाँ मुख्य लेआउट फ़ाइल है पहले बच्चे के लेआउट वजन बनाकर तल पर क्षैतिज पंक्तियों (अंतिम संतान) के रूप में बड़ा दो बार दूसरे बच्चे की:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2">
<TextView
android:text="red"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="green"
android:gravity="center_horizontal"
android:background="#00aa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="blue"
android:gravity="center_horizontal"
android:background="#0000aa"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="yellow"
android:gravity="center_horizontal"
android:background="#aaaa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="row one"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row two"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row three"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row four"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
लेकिन यह मेरे अपेक्षित परिणाम के विपरीत करता है: यह वास्तव में रंगीन सलाखों को लगभग आधा तक लंबवत बनाता है।
एंड्रॉयड डेवलपर दस्तावेज़ निर्दिष्ट करें कि
any remaining space in the view group is assigned to children in the proportion of their declared weight
क्यों यह प्रतीत होता है उलटा तरह सही है? किसी भी शेष अंतरिक्ष पर
यह वास्तव में विपरीत है। जिसे आप बड़ा होना चाहते हैं उसे वजन के रूप में कम संख्या दी जानी चाहिए। – Hiral
@ हायरल इसे वापस करने की देखभाल करते हैं? क्या यह हमेशा सत्य है या केवल जब आप 'fill_parent' का उपयोग करते हैं? मुझे पता है कि जब आप प्रतिस्पर्धी विचारों को – Craigy
@ क्रैगी के साथ शुरू करने के लिए प्रतिस्पर्धात्मक विचार देते हैं तो वास्तव में सच है: वास्तव में मुझे नहीं पता कि यह वास्तव में विभिन्न मामलों के साथ क्या व्यवहार करता है। लेकिन लगभग हर बार, जैसा कि मैंने वर्णन किया है, यह विपरीत कार्य करता है। लेकिन हाँ, कभी-कभी यह अलग-अलग काम करता है। मुझे उस समय कारण पता नहीं था। लेकिन अब मुझे लगता है कि, fill_parent आपके व्यवहार को प्रभावित कर सकता है जैसा आपने कहा था। – Hiral