图片中的ImageView被拉伸 - 机器人机器人、图片、ImageView

2023-09-06 06:26:33 作者:∞ 情人十六

我试图做一个小的图像出现在我的屏幕上。我想这是一个小广场。随着低于code,它显示为长平的矩形。我重视的是它看起来像下面的图片。

I am trying to make a small image appear on my screen. I want it to be a small square. With the below code, it shows up as a long flat rectangle. I have attached a picture of what it looks like below.

的Java code

ImageView q1Image = (ImageView)findViewById(R.id.q1Image);
q1Image.setScaleType(ScaleType.FIT_XY);

XML code

<TableRow
    android:id="@+id/row4"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1" >

    <ImageView
        android:id="@+id/q1Image"
        android:layout_width="10dp"
        android:layout_height="10dp"
        android:layout_weight=".1"
        android:textSize="8sp"
        android:gravity="center_horizontal" />

修改 如果我做的宽度和高度等于 50dp 每个,图像变大,但仍然是一个平坦的期待矩形。

EDIT If I make the width and height equal to 50dp each, the image gets bigger but is still a flat looking rectangle.

推荐答案

FIT_XY将延伸你的形象,以适应所有YOUT ImageView的。 使用规模型fitC​​enter至preserve宽高比将图像中的中心,如果你的ImageView

FIT_XY will stretch your image to fit all yout ImageView. Use scale type fitCenter to preserve aspect ratio by placing the image in center if your ImageView

q1Image.setScaleType(ScaleType.FIT_CENTER);

参见 http://developer.android.com/reference/安卓/空间/ ImageView.ScaleType.html 对于其他的选择。

Refer to http://developer.android.com/reference/android/widget/ImageView.ScaleType.html For other options.