简体   繁体   English

android 图像视图大小不随图像缩放

[英]android image view size does not scale with image

I have the following android layout:我有以下 android 布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainTopLevel"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
>
    <ImageView
        android:id="@+id/orbitImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:scaleType="fitStart"
        android:src="@drawable/earthorbit"
        android:padding="0dp"
        android:background="@android:color/white"
    />
    <TextView
        android:id="@+id/positionDesc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minHeight="40dp"
        android:layout_below="@id/orbitImage"
        android:text="should appear below image"
   />
</RelativeLayout>

The image scales down quite a bit, but since the aspect ratio is maintained, it only takes up the top half of the screen.图像缩小了很多,但由于保持了纵横比,它只占据了屏幕的上半部分。

The problem is that the image view itself has the original height, which takes the entire screen and the text never shows up.问题是图像视图本身具有原始高度,它占据了整个屏幕并且文本永远不会出现。

(So the original image is about 620 X 430, the scaled image is about 250 X 200, but the image view is about 250 X 430) (所以原始图像约为 620 X 430,缩放后的图像约为 250 X 200,但图像视图约为 250 X 430)

Is there a way to get the size of the image view to exactly match the scaled size of the image?有没有办法让图像视图的大小与图像的缩放大小完全匹配?

It looks similar to this problem: Android ImageView size not scaling with source image , to which to the solution was to add android:adjustViewBounds="true" to the ImageView It looks similar to this problem: Android ImageView size not scaling with source image , to which to the solution was to add android:adjustViewBounds="true" to the ImageView

Since the sizes are fixed by the image file in resources, then there is no reason why you should not be able to fix the height on your ImageView: android:layout_height="200dp"由于尺寸是由资源中的图像文件固定的,所以没有理由不能固定 ImageView 的高度: android:layout_height="200dp"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM