2012-03-23 15 views
9

तो, मैं इस लेआउट है:एंड्रॉयड "layout_alignParentBottom" रिश्तेदार लेआउट में

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/layout" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#FFFF00" 
       android:minHeight="100dp" 
       android:layout_gravity="bottom" 
     > 
    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:textColor="#000000" 
      android:background="#FF0000" 
      android:text="Hello World" 
      /> 

    <Button 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_alignParentRight="true" 
      android:text="button"/> 
</RelativeLayout> 

और इस कि यह कैसा दिखता है:

enter image description here

लेकिन अगर मैं बटन को android:layout_alignParentBottom="true" जोड़ने यहाँ है यह कैसा दिखता है:

enter image description here

  1. क्या कोई मुझे इस व्यवहार को समझा सकता है?
  2. पीले लेआउट का आकार बदलने और वर्कअराउंड के लिए हजारों लेआउट जोड़ने के बिना नीचे अपना बटन कैसे रखें?
+0

क्या यह बग अभी भी मौजूद है? –

+0

मुझे एंड्रॉइड 2.2 और 4.0.0 पर इस समस्या का सामना करना पड़ा है, लेकिन मुझे लगता है कि यह अन्य प्लेटफॉर्म पर भी खुश है –

उत्तर

9

इस समाधान मेरे लिए काम किया कोशिश

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/layout" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#FFFF00" 
       android:minHeight="100dp" 
       android:orientation="horizontal" 
       android:layout_gravity="bottom" 
     > 
    <TextView 
      android:id="@+id/tv" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:textColor="#000000" 
      android:background="#FF0000" 
      android:text="Hello World" 
      /> 

    <Button 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_gravity="bottom|right" 
      android:text="button"/> 
</FrameLayout> 
0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="bottom" 
    android:background="#FFFF00" 
    android:minHeight="100dp" > 

    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:textColor="#000000" 
      android:background="#FF0000" 
      android:text="Hello World"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:text="button" /> 

</RelativeLayout> 

इस कोड

+0

आपके कोड का उपयोग करके यह मेरी स्क्रीन को सभी स्क्रीन को कवर करने के लिए बनाता है क्योंकि आपने एंड्रॉइड का उपयोग किया है: layout_height = "fill_parent" और I चाहते हैं कि मेरे लेआउट को मेरी पहली स्क्रीनशॉट –

+0

में देखा गया है, जैसा कि आप कोड नहीं चाहते हैं? – Android

+0

इसलिए मैं चाहता हूं कि मेरा लेआउट मेरी पहली छवि जैसा दिखता हो, सिवाय इसके कि मेरा बटन नीचे से गठबंधन होना चाहिए। –

1

यह एक तेजी से एक स्क्रीन

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="bottom" 
    android:background="#FFFF00" 
    android:minHeight="100dp" > 



    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:text="button" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignTop="@+id/button1" 
     android:background="#000000" 
     android:text="TextView" /> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/button1" 
     android:layout_alignParentLeft="true" 
     android:background="#000000" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:orientation="vertical" > 

    </LinearLayout> 

</RelativeLayout> 
+0

बदलने के लिए आकार moer बटन देते हैं, यह काम नहीं कर रहा है क्योंकि यह मुख्य सापेक्ष लेआउट से मिनीहेइट खाता नहीं रखता है –

1

सिर्फ कोशिश के लिए, आप दोगुना कर सकते हैं मिनट आकार अपने लेआउट का और फिर कोशिश करें? या हो सकता है कि आप लेआउट की हाइट को ठीक कर सकें और आवश्यकता होने पर कोड से गतिशील रूप से बदल सकें।

0

दुर्भाग्यवश बग अभी भी एंड्रॉइड के नए संस्करणों में मौजूद है।

वैसे भी, मैंने पाया है कि इस समस्या का समाधान कर सकते हैं निम्नलिखित:

  1. RelativeLayout की minHeight हटाएँ एक LinearLayout में

  2. सम्मिलित TextView:

    <LinearLayout 
        android:id="@+id/tvLayout" 
        android:layout_alignParentTop="true" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        android:minHeight="100dp" 
        android:gravity="top" 
        > 
        <TextView 
         android:id="@+id/tv" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:background="#FFFF00FF" 
         android:text="Helo" 
         /> 
    </LinearLayout> 
    
  3. बटन से हटाएं layout_alignParentBottom और layout_alignBottom = "@ id/tvLayout"

  4. जोड़ें

अब LinearLayout RelativeLayout की ऊंचाई "नियंत्रण" करता है। यदि टेक्स्ट व्यू ऊंचाई 100 डीपी की न्यूनतम ऊंचाई से बड़ी है, तो यह विस्तारित होगी।

और बटन हमेशा इसके नीचे लाइनरलायआउट को संरेखित कर देगा, रिलेटिव लयआउट के बराबर।