简体   繁体   中英

ImageView is stretch when not supposed to be - Android

Column 0 is supposed to be a picture of either a red x or a green check mark. For testing purposes, I have only put an image in for row 1. As seen in the picture below, the red x image is long and stretched out rectangle. I want it to be a small square image. The image seems to be the same as displayed below even if I put the layout_width and layout_height to 50dp each, 10dp each, or as I have it below in my code. The dimensions of the picture is 100x100 PNG picture -- if that matters.

My question is why is the image to stretched out and how would I go about making it a small square image. Thank you in advance for your help!

Results.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>

在此处输入图片说明

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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