最大宽度和高度为ImageView的Andr​​oid中 [英] Maximum width and height for ImageView in Android

查看:110
本文介绍了最大宽度和高度为ImageView的Andr​​oid中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一个ImageView的设置

 安卓=了maxHeight100像素
机器人:=了maxWidth250像素
机器人:=了minHeight100像素
机器人:=了minWidth250像素
机器人:scaleType =centerInside
 

此图像视图用于显示从画廊或相机获得的图像。在这两种情况下,图像不能调整大小以适合imageview的里面,它只是伸展它的空间一样,因为它需要

不知道如何让它呆在这些界限内?

 < XML版本=1.0编码=UTF-8&GT?;
 

 <的EditText
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =FILL_PARENT
    机器人:ID =@ + ID / txtDescription
    机器人:layout_below =@ + ID / txtSubject
    机器人:inputType =textMultiLine
    机器人:身高=80px
    机器人:提示=@字符串/描述>< /的EditText>

<的EditText
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_below =@ + ID / txtDescription
    机器人:layout_width =FILL_PARENT
    机器人:ID =@ + ID / txtMorada
    机器人:提示=@字符串/地址/>

<的ImageButton
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_below =@ + ID / txtMorada
    机器人:ID =@ + ID / BTGPS
    机器人:layout_alignParentLeft =真
    机器人:SRC =@可绘制/ ic_menu_compass>< / ImageButton的>

< ImageView的
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_below =@ + ID / BTGPS
    机器人:layout_marginTop =25像素
    机器人:ID =@ + ID / imgPoint
    机器人:SRC =@可绘制/ google_logo_small
    机器人:=了maxHeight100像素
    机器人:=了maxWidth250像素
    机器人:=了minHeight100像素
    机器人:=了minWidth250像素
    机器人:scaleType =centerInside>< / ImageView的>

<的ImageButton
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_toRightOf =@ + ID / imgPoint
    机器人:ID =@ + ID / btGallery
    机器人:layout_below =@ + ID / btCamera
    机器人:SRC =@可绘制/ ic_menu_gallery
    机器人:layout_alignParentRight =真正的>< / ImageButton的>

<按钮
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =FILL_PARENT
    机器人:layout_marginTop =10px的
    机器人:ID =@ + ID / btSubmit
    机器人:layout_below =@ + ID / btGallery
    机器人:文本=@字符串/提交>< /按钮>

<的ImageButton
    机器人:layout_height =WRAP_CONTENT
    机器人:ID =@ + ID / btMap
    机器人:layout_below =@ + ID / txtMorada
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_alignParentRight =真
    机器人:SRC =@可绘制/ ic_menu_mapmode>< / ImageButton的>

<的TextView
    机器人:layout_below =@ + ID / txtMorada
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_toLeftOf =@ + ID / btMap
    机器人:layout_height =WRAP_CONTENT
    机器人:ID =@ + ID / lblNewPointLatitude
    机器人:文本=纬度>< / TextView的>

<的TextView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_toLeftOf =@ + ID / btMap
    机器人:layout_height =WRAP_CONTENT
    机器人:ID =@ + ID / lblNewPointLongitude
    机器人:layout_below =@ + ID / lblNewPointLatitude
    机器人:文本=经度>< / TextView的>

<的ImageButton
    机器人:layout_below =@ + ID / btMap
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_toRightOf =@ +是/ imgPoint
    机器人:ID =@ + ID / btCamera
    机器人:layout_marginTop =25像素
    机器人:SRC =@可绘制/ ic_menu_camera
    机器人:layout_alignParentRight =真正的>< / ImageButton的>

<微调
    机器人:layout_height =WRAP_CONTENT
    机器人:ID =@ + ID / spCategoria
    机器人:layout_width =FILL_PARENT
    机器人:提示=@字符串/ spCategoriaPrompt>< /微调>

<微调
    机器人:layout_height =WRAP_CONTENT
    机器人:ID =@ + ID / spSubcategoria
    机器人:layout_below =@ + ID / spCategoria
    机器人:layout_width =FILL_PARENT
    机器人:提示=@字符串/ spSubcategoriaPrompt>< /微调>

<的EditText
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_below =@ + ID / spSubcategoria
    机器人:layout_width =FILL_PARENT
    机器人:ID =@ + ID / txtSubject
    机器人:提示=@字符串/主题>< /的EditText>

  < / RelativeLayout的>
< /滚动型>
 

解决方案

尝试<一href="http://developer.android.com/reference/android/widget/ImageView.html#attr_android%3aadjustViewBounds"><$c$c>adjustViewBounds属性:

 安卓adjustViewBounds =真
 

So I have an ImageView set with

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

This image view is used to show a picture that is obtained from the gallery or camera. In both cases, the image is not resized to fit inside the imageview, it just stretches its space as much as it needs.

Any idea how to make it stay inside those bounds?

<?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>

解决方案

Try the adjustViewBounds attribute:

android:adjustViewBounds="true"

这篇关于最大宽度和高度为ImageView的Andr​​oid中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆