繁体   English   中英

当不应该使用ImageView时会拉伸-Android

[英]ImageView is stretch when not supposed to be - Android

列0应该是红色x或绿色复选标记的图片。 出于测试目的,我仅在第1行放置了一个图像。如下图所示,红色的x图像很长并且呈矩形展开。 我希望它是一个小的正方形图像。 即使我将layout_width和layout_height分别设置为50dp,10dp或代码如下所示,该图像似乎也与下面显示的图像相同。 图片的尺寸为100x100 PNG图片-如果这样的话。

我的问题是为什么图像要拉伸,如何将其制作成小正方形图像。 预先感谢您的帮助!

结果.java

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

resultsmain.xml

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

    <ImageView
        android:id="@+id/q1Image"
        android:layout_width="5dp"
        android:layout_height="10dp"
        android:layout_weight=".1" />

    <TextView
        android:id="@+id/q1Question"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight=".5"
        android:textSize="8sp" />

    <TextView
        android:id="@+id/q1Answer"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:textSize="8sp"
        android:gravity="center_horizontal" />

    <TextView
        android:id="@+id/q1Verse"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:textSize="8sp"
        android:gravity="center_horizontal" />
</TableRow>

在此处输入图片说明

尝试这个:

<TableRow
    android:id="@+id/row4"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:stretchColumns="0,1,2,3"
    android:weightSum="1" >

    <ImageView
        android:id="@+id/q1Image"
        android:layout_width="5dp"
        android:layout_height="10dp"
        android:layout_weight=".1"
       />

    <TextView
        android:id="@+id/q1Question"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight=".5"
        android:textSize="8sp" />

    <TextView
        android:id="@+id/q1Answer"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:textSize="8sp"
        android:gravity="center_horizontal" />

    <TextView
        android:id="@+id/q1Verse"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:textSize="8sp"
        android:gravity="center_horizontal" />
</TableRow>

暂无
暂无

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

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