Java 图像视图不包装内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21203189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Image View not Wrapping Contents
提问by Tyler Sebastian
I've got an ImageView wrapping this image:
我有一个 ImageView 包装这个图像:
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:scaleType="fitStart"
android:src="@drawable/oncmap"/>
and right below it, a TextView. Unfortunately, it either pushes it down the view or out of the view depending on the device's screen size.
在它的正下方,一个 TextView。不幸的是,根据设备的屏幕尺寸,它要么将其推下视图,要么将其推出视图。
http://i.imgur.com/CuVFK5P.png
http://i.imgur.com/CuVFK5P.png
http://i.imgur.com/6wzMebV.jpg
http://i.imgur.com/6wzMebV.jpg
I can "hack" it, but it'd rather not...
我可以“破解”它,但它宁愿不...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="16dp"
android:orientation="vertical"
tools:context="MapFragment">
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/oncmap"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Neptune"
style="@style/sectionHeader"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="16dp"
android:text="@string/info"
style="@style/text"/>
采纳答案by sachin10
Add the following fields to ImageView:
将以下字段添加到 ImageView:
android:scaleType="fitXY"
android:adjustViewBounds="true"
回答by Lavish Garg
if you try to add the large size image for eg let say 4~6 mb and you are using the drawable,then you would get the error like->java.lang.RuntimeException: Canvas: trying to draw too large(537528960bytes) bitmap
如果您尝试添加例如 4~6 mb 的大尺寸图像并且您正在使用 drawable,那么您会收到类似错误 -> java.lang.RuntimeException: Canvas: 尝试绘制太大(537528960bytes) 位图
For java do this in your android studio, but the concept remains same for others also,do this to insert the image in your app in the background, applicable for both large and small size images.
对于 java 在您的 android studio 中执行此操作,但其他人的概念也保持不变,这样做是为了在您的应用程序中在后台插入图像,适用于大尺寸和小尺寸的图像。
Basically move your image in the (hi-res) drawable to drawable-xxhdpiwhich would be finded by going in the app->res->mipmap.
基本上将(高分辨率)drawable 中的图像移动到 drawable-xxhdpi,这可以通过进入 app->res->mipmap 找到。
<ImageView
android:id="@+id/imageView2"
android:layout_width="0dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/imagename" />