2012-10-27 10 views
6

मुझे दो फॉर्म विगेट्स के साथ एक साधारण लेआउट बनाना होगा (उदाहरण के लिए - दो बटन)। पहले व्यक्ति को मूल लेआउट की सभी उपलब्ध चौड़ाई भरनी होगी और दूसरे के पास कुछ निश्चित आकार होना चाहिए।एंड्रॉइड: यह सरल लेआउट कैसे बनाएं?

मैं क्या जरूरत है कि: enter image description here

अगर मैं पहले विजेट को FILL_PARENT सेट - मैं एक दूसरे के नहीं दिख रहा। यह सिर्फ लेआउट के दृश्य क्षेत्र से दूर उड़ता है :) मुझे नहीं पता कि इसे कैसे ठीक किया जाए ...

उत्तर

14

यह करने के लिए सबसे आसान तरीका है LinearLayout साथ layout_weight उपयोग कर रहा है। ध्यान दें कि पहले टेक्स्ट व्यू की चौड़ाई "0dp" है, जिसका अर्थ है "मुझे अनदेखा करें और वजन का उपयोग करें"। वजन किसी भी संख्या हो सकता है; चूंकि यह एकमात्र भारित दृश्य है, यह उपलब्ध स्थान भरने के लिए विस्तारित होगा।

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    > 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     /> 
    <TextView 
     android:layout_width="25dp" 
     android:layout_height="wrap_content" 
     /> 
</LinearLayout> 
+0

धन्यवाद! यही वही है जो मुझे चाहिए! – JavaRunner

1

आप इसे रिलेटिव लयआउट या फ़्रेमलाउट के साथ पूरा कर सकते हैं।

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="5dp" 
     android:layout_marginLeft="5dp" 
     android:background="#ccccee" 
     android:text="A label. I need to fill all available width." /> 

    <TextView 
     android:layout_width="20dp" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="5dp" 
     android:paddingRight="5dp" 
     android:background="#aaddee" 
     android:text=">>" /> 

</RelativeLayout> 

How the layout looks

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