2012-10-22 28 views
6

मैं एक ऐसा प्रतिरूप कुछ इस तरह दिखता प्राप्त करने के लिए कोशिश कर रहा हूँ:RelativeLayout में layout_alignBaseline और layout_alignBottom का उपयोग करते हुए एक साथ

Relative layout example

यही कारण है:

  1. TextView (मार्जिन के साथ) गठबंधन माता-पिता के लिए बाएं और ऊपर
  2. TextView के बाईं ओरके दाईं ओर EditText और TextView के साथ बेसलाइन-गठबंधन।
  3. Button अभिभावक दाहिनी ओर गठबंधन (केवल सही मार्जिन के साथ)। और यहां टूटा हुआ हिस्सा है: EditText पर नीचे गठबंधन।

किसी भी कारण से यह काम नहीं करता है।

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="32dp" 
     android:layout_marginTop="32dp" 
     android:text="Text:" /> 

    <EditText 
     android:id="@+id/edit" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/text" 
     android:layout_toLeftOf="@+id/button" 
     android:layout_toRightOf="@+id/text" 
     android:ems="10" > 

     <requestFocus /> 
    </EditText> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignBottom="@+id/edit" 
     android:layout_marginRight="32dp" 
     android:text="Ok" /> 

</RelativeLayout> 

कि इस तरह बाहर आता है:

Broken RelativeLayout

पर क्या हो रहा है यहाँ कोड मैं काम करने के लिए उम्मीद थी है?

संपादित

क्षमा मुझे यकीन है कि मैं क्यों इस उदाहरण बदल नहीं कर रहा हूँ, लेकिन मेरे कोड में मैं वास्तव में एक ImageButton, नहीं Button उपयोग कर रहा हूँ, तो समाधान बटन के आधारभूत साथ संरेखित शामिल नहीं कर सकता - EditText को बटन के नीचे (या यदि संभव हो तो मध्यम) के साथ गठबंधन किया जाना चाहिए।

+0

थीम से आने वाला मार्जिन हो सकता है? – njzk2

+0

नहीं ............ – Timmmm

उत्तर

4

इस प्रयास करें ..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<TextView 
    android:id="@+id/text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="32dp" 
    android:layout_marginTop="32dp" 
    android:text="Text:" /> 


<EditText 
    android:id="@+id/edit" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/text" 
    android:layout_toLeftOf="@+id/button" 
    android:layout_toRightOf="@+id/text" 
    android:ems="10" > 

    <requestFocus /> 
</EditText> 

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/edit" 
    android:layout_alignBottom="@+id/edit" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="30dp" 
    android:text="Ok" /> 

+0

असल में यह काम करता है, लेकिन केवल इसलिए कि बटन की आधार रेखा है, मैंने अपने प्रश्न में एक बुरा उदाहरण दिया (क्षमा करें!) - असल में मैं 'छविबटन' का उपयोग कर रहा हूं, नहीं एक 'बटन'। – Timmmm

+0

तो क्या? यह इमेजबटन के साथ भी काम करेगा। संरेखण बेसलाइन + alignBottom हमेशा 1 लाइन के नीचे होगा – AndrewS