2010-12-02 25 views
7

मैं 3 लाइनरलाइट्स को व्यवस्थित करने की कोशिश कर रहा हूं, जैसे कि बायीं तरफ उचित है, एक दाईं ओर, और तीसरा दोनों तरफ बराबर रिक्त स्थान के साथ दोनों के बीच है। मुझे लगता है कि मैं इसे पूरा करने के लिए एक रिलेटिवलाउट में लपेटता हूं। फिर संरेखित करने के लिए एक लेआउट सेट करें और पैरेंट राइट संरेखित करने के लिए दूसरा लेआउट सेट करें। लेकिन तीसरे लेआउट के लिए, मैं layout_marginLeft = (RelativeLayout.width - (layout1.width + layout2.width + layout3.width) सेट करना चाहता हूं)/2। हालांकि, मुझे नहीं लगता कि यह xml में कैसे करें। कोई सुझाव?एंड्रॉइड: रिलेवेटिवआउट के भीतर समान रूप से अंतरिक्ष घटक कैसे?

* संपादित करें। सुझावों के आधार पर, अब मैं एक लीनियरलाउट का उपयोग कर रहा हूं। यह काम करने के करीब है, लेकिन 3 लेआउट समान रूप से दूरी पर नहीं हैं, और सही लेआउट सही नहीं है।

<LinearLayout 
     android:id="@+id/toolbar" 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:paddingTop="4dip" 
     android:paddingBottom="4dip" 
     android:background="#50000000" 
     android:visibility="visible"> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_weight="1" 
      android:layout_height="wrap_content"> 
       <ImageButton 
        android:id="@+id/open" 
        android:src="@drawable/open" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"> 
       </ImageButton> 
     </LinearLayout> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_weight="1" 
      android:layout_height="wrap_content"> 
      <ImageButton 
       android:id="@+id/prev" 
       android:src="@drawable/prev" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
      </ImageButton> 
      <TextView 
       android:id="@+id/totalpages" 
       android:text="0 of 0" 
       android:layout_gravity="center" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="#FFFFFFFF"> 
      </TextView> 
      <ImageButton 
       android:id="@+id/next" 
       android:src="@drawable/next" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
      </ImageButton> 
     </LinearLayout> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_gravity="right" 
      android:layout_width="wrap_content" 
      android:layout_weight="1" 
      android:layout_height="wrap_content"> 
      <ImageButton 
       android:id="@+id/zoomout" 
       android:src="@drawable/zoomout" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
      </ImageButton> 
      <ImageButton 
       android:id="@+id/zoomin" 
       android:src="@drawable/zoomin" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
      </ImageButton> 
     </LinearLayout> 
    </LinearLayout> 

उत्तर

12

RelativeLayout के बजाय एक LinearLayout का प्रयोग करें और layout_weight विशेषता का उपयोग: नीचे मेरी एक्सएमएल है। आप 0dip के लिए और फिर कुछ ऐसा करने के लिए वजन सेट layout_width स्थापित करने के लिए आवश्यकता हो सकती है 0.33

संपादित करें: हाँ आप एक वजन 1 या नीचे 1. उदाहरण किसी अन्य बराबर वजन का उपयोग कर सकते

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     > 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="string 1 for test...." 
      /> 
    </LinearLayout> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     > 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
      android:text="string 2 for test...." 
      /> 
    </LinearLayout> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     > 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
     android:layout_gravity="right" 
      android:text="string 3 for test...." 
      /> 
    </LinearLayout> 
</LinearLayout> 
+0

बस इस उत्तर में शामिल होने के लिए: एक लीनियरलाउट (एक लीनियरलाउट के भीतर तीन लीनियरलाइट्स) के साथ जाएं, सभी चौड़ाई को fill_parent पर सेट करें, और आंतरिक तीन लेआउट 'एंड्रॉइड दें: layout_weight =" 1 "'। – kcoppock

+0

धन्यवाद, यह मुझे करीब मिला है, लेकिन मेरे लिए काफी काम नहीं करता है। यह 3 लाइनरलेआउट्स को एक ही आकार के लिए मजबूर करता है, लेकिन मेरे लाइनरलेआउट में अलग-अलग सामग्री होती है। कृपया मेरा संपादन देखें। – ab11

+0

तो आपके पास तीन बटन हैं और मैं अनुमान लगा रहा हूं कि उन तीन बटन एक ही चौड़ाई के नहीं हैं। यह एक मुश्किल मामला होगा। मैं छवि आकार को कम करने का सुझाव दूंगा ताकि सभी बटन अच्छे लगें और फसल न जाए। उदाहरण के लिए ट्विटर/फेसबुक ऐप देखें। यदि यह संभव नहीं है तो तय करें कि प्रत्येक बटन की न्यूनतम चौड़ाई क्या होनी चाहिए और उन्हें निर्दिष्ट करें [स्क्रीन आकार पर भी निर्भर करता है]। और इसके बाद मैं सुझाव दे सकता हूं कि उसके आसपास खेलना और देखें कि आपके लिए सबसे अच्छा क्या काम करता है। – achie

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