2013-04-17 9 views
5

मुझे RelativeLayout में स्क्रीन के बाहर समस्या बटन शो के साथ सामना करना पड़ रहा है। ImageView कोई बटन दृश्यमान स्थान देने के लिए चित्र स्केल नहीं करता है।मैं स्क्रीन पर रिलेवेटलाइट कैसे फिट कर सकता हूं?

मैं क्या है:

enter image description here

मुझे क्या करना चाहते हैं:

enter image description here

कोड:

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

<TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:textAppearance="@android:style/TextAppearance.Small" 
     android:textColor="?android:attr/textColorTertiary" 
     android:layout_centerHorizontal="true" 
     /> 

<ru.mw.widget.DrawableImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView" 
     android:adjustViewBounds="true" 
     android:layout_centerHorizontal="true" 
     android:scaleType="centerCrop" 
     /> 

<Button 
     android:id="@+id/processButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:layout_below="@+id/imageView" 
     android:layout_centerHorizontal="true" 
     /> 

समस्या जब मैं स्क्रीन ओरिएंटेशन बदलने: अगर मैं लैंडस्केप मोड में सब कुछ Arun C Thomas's method का उपयोग ठीक है, लेकिन पोर्ट्रेट मोड में मैं इस (बाएं/सही किनारों से काटी छवि) है:

enter image description here क्या उम्मीद है:

बटन को android:layout_alignParentBottom="true" जोड़ने के लिए

enter image description here

+0

एंड्रॉयड जोड़े के बीच ImageView: अपने बटन को alignParentBottom, और एंड्रॉयड: alignParentTop (दोनों = true) अपने TextView करने के लिए। आप इस समय अपनी छवि दृश्य के लिए कोई सीमा निर्धारित नहीं कर रहे हैं। –

उत्तर

2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center_vertical" > 

<TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:textColor="?android:attr/textColorTertiary" 
     android:textAppearance="@android:style/TextAppearance.Small" 

     android:layout_centerHorizontal="true" 
     /> 

<ru.mw.widget.DrawableImageView 
    android:id="@+id/imageView" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_below="@+id/textView" 
    android:layout_centerHorizontal="true" 
    android:adjustViewBounds="true" 
    android:scaleType="centerCrop" 
    android:layout_above="@+id/processButton" 
    /> 

<Button 
     android:id="@+id/processButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     /> 
</RelativeLayout> 

यह समाधान

अब प्राप्त करने के लिए अपडेट किया गया आवश्यकता res में layout-land फ़ोल्डर में ऊपर लेआउट जोड़ने (यदि आपके पास एक फ़ोल्डर नामित res में layout-land बनाने की जरूरत नहीं है) अब डिफ़ॉल्ट रूप में layout फ़ोल्डर जोड़ने है यह xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" > 
<ru.mw.widget.DrawableImageView 
    android:id="@+id/imageView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:adjustViewBounds="true" 
    /> 

<Button 
    android:id="@+id/processButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/imageView" 
    android:layout_centerHorizontal="true" 
    android:text="@string/str" /> 

<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/imageView" 
    android:layout_centerHorizontal="true" 
    android:text="@string/str" 
    android:textColor="?android:attr/textColorTertiary" /> 

</RelativeLayout> 

यह है।

+0

अच्छा उदाहरण, +1, लेकिन मैं अपने प्रश्न को थोड़ा सा संपादित करता हूं ... – ADK

+0

उत्तर संपादित किया गया कृपया –

+0

देखें मुझे आशा है कि यह एक लेआउट के साथ हासिल किया जा सकता है, लेकिन आपका सही है, धन्यवाद! – ADK

1

प्रयास करें:

<Button 
    android:id="@+id/processButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/str" 
    android:layout_below="@+id/imageView" 
    android:layout_centerHorizontal="true" 
    android:layout_alignParentBottom="true" 
    /> 
1
  1. layout_alignParentBottom="true" का उपयोग करके पैरेंट तल पर बटन को संरेखित करें।
  2. लपेटें TextView और Button

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

<TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:textAppearance="@android:style/TextAppearance.Small" 
     android:textColor="?android:attr/textColorTertiary" 
     android:layout_centerHorizontal="true" 
     /> 

<Button 
     android:id="@+id/processButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     /> 

<ru.mw.widget.DrawableImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView" 
     android:layout_above="@+id/processButton" 
     android:adjustViewBounds="true" 
     android:layout_centerHorizontal="true" 
     android:scaleType="centerCrop" 
     /> 

</RelativeLayout> 
संबंधित मुद्दे