2013-08-29 7 views
11

में ओवरलैपिंग से विचारों को रोकें मैं एक एंड्रॉइड एप्लिकेशन विकसित करने की कोशिश कर रहा हूं, लेकिन मुझे जीयूआई डिज़ाइन के साथ कुछ समस्याएं आ रही हैं। स्क्रीनशॉट का निम्नलिखित भाग मेरी समस्या है (एंड्रॉइड डीबग विकल्पों द्वारा लाल और नीली रेखाएं उत्पन्न की गईं)।RelativeLayout

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/caption" 
    android:layout_below="@+id/caption" > 

    <ImageButton 
     android:id="@+id/button_edit" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/content_edit" 
     style="?android:attr/borderlessButtonStyle" /> 

    <TextView 
     android:id="@+id/myText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:text="@string/num_placeholder" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 


</RelativeLayout> 

आप देख सकते हैं, TextView myText ImageButton button_edit ओवरलैप होता है:

my problem

इस कोड है। एक सापेक्ष समाधान एक रिलेवेटिवआउट के बजाय लाइनरलाइट का उपयोग करना होगा।

  1. मैं सही
  2. मैं पाठ की जरूरत है

मैं भी (संपादित करें बटन जाहिर की बाईं ओर) लेआउट के बाकी को भरने के लिए पर संपादित करें बटन की जरूरत है: समस्या यह है कि है myText के layout_width को 'fill_parent' पर सेट करने का प्रयास किया, लेकिन यह संपादन बटन के बाईं ओर पूरी स्क्रीन को भर देता है।

अपेक्षित व्यवहार (एक दो लाइनों TextView बनने) के बजाय 'button_edit'

किसी को भी मेरी मदद कर सकते ओवरलैपिंग अपनी ऊंचाई बढ़ाने के लिए myText किया जाएगा? धन्यवाद

TextView लेआउट में
+0

आप 'रिलेवेटिवआउट' का उपयोग क्यों करना चाहते हैं जब इसे 'लीनियरलाउट' के साथ हासिल किया जा सकता है? – sriramramani

उत्तर

19

उपयोग layout_toLeftOf

इस तरह:

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_alignLeft="@+id/caption" 
android:layout_below="@+id/caption" > 

<ImageButton 
    android:id="@+id/button_edit" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:layout_alignParentRight="true" 
    android:src="@drawable/content_edit" 
    style="?android:attr/borderlessButtonStyle" /> 

<TextView 
    android:id="@+id/myText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_centerVertical="true" 
    android:text="@string/num_placeholder" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_toLeftOf="@+id/button_edit" /> 

+0

धन्यवाद! यह पूरी तरह से काम करता है! – Gnufabio

+0

क्या होगा यदि हम इसे गतिशील रूप से दृश्यों के साथ प्राप्त करना चाहते हैं? –

0

करने का एक और तरीका है एंड्रॉयड उपयोग करने के लिए है: layout_toEndOf विशेषता

<ImageButton 
    android:id="@+id/button_edit" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:layout_alignParentRight="true" 
    android:src="@drawable/content_edit" 
    style="?android:attr/borderlessButtonStyle" 
    android:layout_toEndOf="@+id/myText" /> 

<TextView 
    android:id="@+id/myText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_centerVertical="true" 
    android:text="@string/num_placeholder" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

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