2010-11-24 11 views
59
में अधिकतम चौड़ाई और imageView के लिए ऊंचाई

तो मैंएंड्रॉयड

android:maxHeight="100px" 
android:maxWidth="250px" 
android:minHeight="100px" 
android:minWidth="250px" 
android:scaleType="centerInside" 

के साथ एक imageView सेट इस छवि को देखने के लिए एक तस्वीर है कि गैलरी या कैमरे से प्राप्त किया जाता है को दिखाने के लिए प्रयोग किया जाता है है। दोनों मामलों में, छवि को छविदृश्य के अंदर फिट करने के लिए आकार में नहीं बदला जाता है, यह केवल अपनी जगह जितनी जरूरत हो उतनी जगह फैलाता है।

कोई विचार यह है कि इसे उन सीमाओं के अंदर कैसे बनाया जाए?

<?xml version="1.0" encoding="utf-8"?> 

<EditText 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:id="@+id/txtDescription" 
    android:layout_below="@+id/txtSubject" 
    android:inputType="textMultiLine" 
    android:height="80px" 
    android:hint="@string/description"></EditText> 

<EditText 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/txtDescription" 
    android:layout_width="fill_parent" 
    android:id="@+id/txtMorada" 
    android:hint="@string/address" /> 

<ImageButton 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_below="@+id/txtMorada" 
    android:id="@+id/btGPS" 
    android:layout_alignParentLeft="true" 
    android:src="@drawable/ic_menu_compass"></ImageButton> 

<ImageView 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_below="@+id/btGPS" 
    android:layout_marginTop="25px" 
    android:id="@+id/imgPoint" 
    android:src="@drawable/google_logo_small" 
    android:maxHeight="100px" 
    android:maxWidth="250px" 
    android:minHeight="100px" 
    android:minWidth="250px" 
    android:scaleType="centerInside"></ImageView> 

<ImageButton 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_toRightOf="@+id/imgPoint" 
    android:id="@+id/btGallery" 
    android:layout_below="@+id/btCamera" 
    android:src="@drawable/ic_menu_gallery" 
    android:layout_alignParentRight="true"></ImageButton> 

<Button 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_marginTop="10px" 
    android:id="@+id/btSubmit" 
    android:layout_below="@+id/btGallery" 
    android:text="@string/submit"></Button> 

<ImageButton 
    android:layout_height="wrap_content" 
    android:id="@+id/btMap" 
    android:layout_below="@+id/txtMorada" 
    android:layout_width="wrap_content" 
    android:layout_alignParentRight="true" 
    android:src="@drawable/ic_menu_mapmode"></ImageButton> 

<TextView 
    android:layout_below="@+id/txtMorada" 
    android:layout_width="wrap_content" 
    android:layout_toLeftOf="@+id/btMap" 
    android:layout_height="wrap_content" 
    android:id="@+id/lblNewPointLatitude" 
    android:text="Latitude"></TextView> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_toLeftOf="@+id/btMap" 
    android:layout_height="wrap_content" 
    android:id="@+id/lblNewPointLongitude" 
    android:layout_below="@+id/lblNewPointLatitude" 
    android:text="Longitude"></TextView> 

<ImageButton 
    android:layout_below="@+id/btMap" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_toRightOf="@+is/imgPoint" 
    android:id="@+id/btCamera" 
    android:layout_marginTop="25px" 
    android:src="@drawable/ic_menu_camera" 
    android:layout_alignParentRight="true"></ImageButton> 

<Spinner 
    android:layout_height="wrap_content" 
    android:id="@+id/spCategoria" 
    android:layout_width="fill_parent" 
    android:prompt="@string/spCategoriaPrompt"></Spinner> 

<Spinner 
    android:layout_height="wrap_content" 
    android:id="@+id/spSubcategoria" 
    android:layout_below="@+id/spCategoria" 
    android:layout_width="fill_parent" 
    android:prompt="@string/spSubcategoriaPrompt"></Spinner> 

<EditText 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/spSubcategoria" 
    android:layout_width="fill_parent" 
    android:id="@+id/txtSubject" 
    android:hint="@string/subject"></EditText> 

    </RelativeLayout> 
</ScrollView> 
+1

क्या लेआउट imageView आसपास है? क्या आप एक्सएमएल का एक बड़ा स्निपेट पोस्ट कर सकते हैं? –

+1

आपको वास्तव में अपने एक्सएमएल में इंडेंटेशन के साथ लाइन ब्रेक भी जोड़ना चाहिए। यह असंभव है जैसा है। एक बात जो मैंने देखा वह बीटी कैमरे टेक्स्ट व्यू में था: आपका लेआउट_to राइटऑफ कहता है कि '@ + आईडी' के बजाय '@ + is' है। यह आपकी मुख्य समस्या नहीं है, बेशक, लेकिन यह आपके लेआउट को प्रभावित करेगा। – kcoppock

+0

संभव डुप्लिकेट [एंड्रॉइड छविदृश्य maxwidth का सम्मान नहीं कर रहा है?] (Http://stackoverflow.com/questions/3530328/android-imageview-not-respecting-maxwidth) –

उत्तर

165

adjustViewBounds विशेषता का प्रयास करें xmlns:android="http://schemas.android.com/apk/res/android" उदाहरण:

<ImageView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/imageView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:maxHeight="400dp" 
    android:adjustViewBounds="true" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:src="@drawable/background_img" 
    /> 
+0

यह सही उत्तर है। धन्यवाद – MBH

5

आप android:scaleType="fitCenter" की कोशिश की है? के रूप में आप चौड़ाई और ऊंचाई के लिए स्पष्ट मान सेटिंग के अलावा wrap_content करने के लिए दोनों layout_width और layout_height सेट है, मायरा

8

द्वारा बताया इसके अलावा देखने के आयाम wrap_content के लिए सेट नहीं किया जाना चाहिए। इसके बजाय, आपको केवल कुछ संख्या मान के लिए layout_width और layout_height सेट करना चाहिए। इसके अलावा, पीएक्स के बजाय डीपी का उपयोग करें। supporting multiple screen sizes देखें। इस सहित

android:adjustViewBounds="true" 
+0

आप इस संदर्भ में पूर्णांक मानों में layout_width/ऊंचाई सेट नहीं कर सकते हैं। –