草庐IT

android - Android中ImageView的最大宽度和高度

coder 2023-05-08 原文

所以我用

设置了一个 ImageView
android:maxHeight="100px"
android:maxWidth="250px"
android:minHeight="100px"
android:minWidth="250px"
android:scaleType="centerInside"

此 ImageView 用于显示从图库或相机中获取的图片。在这两种情况下,图像都不会调整大小以适应 imageview,它只是根据需要拉伸(stretch)其空间。

知道如何让它保持在这些范围内吗?

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

最佳答案

试试 adjustViewBounds属性:

android:adjustViewBounds="true"

关于android - Android中ImageView的最大宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4270394/

有关android - Android中ImageView的最大宽度和高度的更多相关文章

  1. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  2. ruby-on-rails - 需要帮助最大化多个相似对象中的 3 个因素并适当排序 - 2

    我需要用任何语言编写一个算法,根据3个因素对数组进行排序。我以度假村为例(如Hipmunk)。假设我想去度假。我想要最便宜的地方、最好的评论和最多的景点。但是,显然我找不到在所有3个中都排名第一的方法。Example(assumingthereare20importantattractions):ResortA:$150/night...98/100infavorablereviews...18of20attractionsResortB:$99/night...85/100infavorablereviews...12of20attractionsResortC:$120/night

  3. ruby - 获取数组中值的最大连续出现次数 - 2

    下面有没有更优雅的方法来实现这个:输入:array=[1,1,1,0,0,1,1,1,1,0]输出:4我的算法:streak=0max_streak=0arr.eachdo|n|ifn==1streak+=1elsemax_streak=streakifstreak>max_streakstreak=0endendputsmax_streak 最佳答案 类似于w0lf'sanswer,但通过从chunk返回nil来跳过元素:array.chunk{|x|x==1||nil}.map{|_,x|x.size}.max

  4. Ruby:检查东亚宽度 (Unicode) - 2

    使用Ruby,我必须将字符串以柱状格式输出到终端。像这样:|row1|astringhere|etc|row2|anotherstring|etc我可以使用String#ljust和%s处理拉丁UTF8字符。但是当字符是韩文、中文等时就会出现问题。当英文行与包含韩文等的行交错时,列根本不会对齐。如何在此处实现列对齐?有没有办法以等同于固定宽度字体的方式输出亚洲字符?对于要在Vim中显示和编辑的文档怎么样? 最佳答案 您的问题发生在CJK(中文/日文/韩文)full-widthandwidecharacters(也向下滚动图表);这些

  5. ruby - capybara 增加最大允许页面加载时间 - 2

    我有一个页面,有时加载时间超过一分钟。假设这是预期的行为并且不会改变。在这些情况下,我得到Net::ReadTimeout。请注意,这是在通过单击上一页上的按钮导航到页面之后,而不是ajax请求。因此Capybara.using_wait_time没有帮助。我尝试了一些激进的方法(其中一些我知道行不通),例如:设置page.driver.browser.manage.timeouts的implicit_wait、script_timeout和page_load。遍历整个对象空间并设置所有Selenium::WebDriver::Remote::Http::Default的timeout

  6. Ruby - 找到哈希最大值的键 - 2

    我有一个散列,我想返回散列最大值的键(或键/值对)。所以,如果只有一个真正的最大值,它将返回那个键;但是,如果有多个具有相同值的键/值对,它将返回所有这些键。我如何在Ruby中完成此操作?my_hash.max_by{|k,v|v}#onlyreturnsonekey/valuepair 最佳答案 如果你想要所有对,我会做类似的事情max=my_hash.values.maxHash[my_hash.select{|k,v|v==max}] 关于Ruby-找到哈希最大值的键,我们在Sta

  7. Ruby:获取具有最大值的哈希对 - 2

    这是一个哈希值,用于跟踪我拥有的每种水果的数量fruits={"apples"=>10,"pears"=>15,"bananas"=>15,"grapes"=>12}我想知道哪种水果我吃得最多。如果有决胜局,则将它们全部归还。 最佳答案 #easymax_quantity=fruits.values.maxmax_fruits=fruits.select{|k,v|v==max_quantity}.keys#fastmax_quantity=-1.0/0.0max_fruits=[]fruits.eachdo|k,v|ifv>max

  8. ruby-on-rails - 如何在 ruby​​ 中找到跨记录的最大属性? - 2

    我有几个具有多个属性(A、B、C、D)的记录。我希望能够找到哪条记录对于给定属性(例如D)具有更高的值。我该怎么做? 最佳答案 你可能会给出max_by一看。objects=[somearrayofobjects]object_with_highest_value=objects.max_by{|obj|obj.desired_value} 关于ruby-on-rails-如何在ruby​​中找到跨记录的最大属性?,我们在StackOverflow上找到一个类似的问题:

  9. ruby - 如何获取两个数组之间的最大值数组 - 2

    我正在寻找一种优雅的方法来获取包含两个数组之间最大值的数组。意思是如果有两个数组:a=[1,5,9]b=[3,2,11]结果应该是:=>[3,5,11]假设两个数组的大小相同。我使用的代码感觉不像是用Ruby的方式来完成这个任务:c=Array.new(a.size)foriin0...a.sizec[i]=[a[i],b[i]].maxend 最佳答案 这应该有效:[a,b].transpose.map(&:max)#=>[3,5,11]transpose返回[[1,3],[5,2],[9,11]]和map(&:max)找到每个子

  10. ruby - 我如何在 Ruby 中计算字符串的宽度? - 2

    String.length只会告诉我字符串中有多少个字符。(其实在Ruby1.9之前,它只会告诉我多少个字节,这就更没用了。)我真的很想知道一个字符串有多少个“en”宽。例如:'foo'.width#=>3'moo'.width#=>3.5#m's,w's,etc.arewide'foi'.width#=>2.5#i's,j's,etc.arenarrow'foobar'.width#=>6.25#spacesareverynarrow如果我能得到字符串的第一个n就更好了:'foo'[0,2.en]#=>"fo"'filial'[0,3.en]#=>"fili"'foobarbaz'[

随机推荐