में समान रूप से स्थानांतरित बटन मैं एंड्रॉइड पर पोर्ट्रेट व्यू में समान रूप से दूरी वाले 4 बटन बनाने की कोशिश कर रहा हूं।लेआउट
अंतरिक्ष को स्क्रीन आकार के आधार पर ऊपर और नीचे स्केल करना चाहिए, प्रत्येक बटन और सीमाओं के बीच की एक भी मात्रा में स्थान के साथ।
मैंने रैखिक लेआउट, वजन और लेआउट गुरुत्वाकर्षण का उपयोग करने की कोशिश की लेकिन ऐसा लगता है कि मैं लंबवत बटन को केंद्र में नहीं रख सकता।
क्या यह एंड्रॉइड लेआउट का एक बग है? शायद मैं सिर्फ मुझे है।
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center"
>
<Button
android:id="@+id/btn_f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn_f"
>
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center"
>
<Button
android:id="@+id/btn_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn_b"
>
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center"
>
<Button
android:id="@+id/btn_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn_a"
>
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center"
>
<Button
android:id="@+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings"
>
</Button>
</LinearLayout>
</LinearLayout>
इस तरह यह काम नहीं करता ... लेकिन यदि आप दोनों लेआउट_ग्रैविटी और गुरुत्वाकर्षण केंद्र के रूप में निर्दिष्ट करते हैं तो यह काम करता है .... निश्चित एंड्रॉइड एक्सएमएल इंटरफेस के लिए POORLY दस्तावेज है .... – Mascarpone
यह एंड्रॉइड होना चाहिए: layout_gravity = "center" एंड्रॉइड नहीं: गुरुत्वाकर्षण = "केंद्र"। एंड्रॉइड का उपयोग करना आवश्यक नहीं है: गुरुत्वाकर्षण = "केंद्र" यहां। गुरुत्वाकर्षण टैग इसकी सामग्री को पोजीशन करने पर प्रभाव डालता है जबकि लेआउट_ग्रैविटी अपने माता-पिता के संबंध में स्थिति को प्रभावित करता है। – wooohoh