سؤال

So when I wrap content over my lock drawable, for some reason the drawable stretches itself horizontally in the TableLayout I have defined. I know it's not the image itself because I have tested this in the LinearLayout and the image displays completely fine. Here's my code:

<?xml version="1.0" encoding="utf-8"?>

<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/metastatisticsscreen"
    android:paddingTop="0dp"
     >
<TableRow
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:background="#45c9ff"
    android:layout_marginBottom="3dp"
    android:gravity="center_horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/achievement"
        android:textColor="#FFFFFF"
        android:textSize="50sp" />

</TableRow>


<TableRow
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF">

    <ImageView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/lock"/>

    <TextView
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:text="@string/additionachievement1descript"/>

    </TableRow>



</TableLayout>

The problem is the lock drawable stretches itself horizontally. Any fix
هل كانت مفيدة؟

المحلول

A possible solution:

    <ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:background="@drawable/lock"
    android:scaleType="centerInside"/>

There are othe scale types, test them until it belongs to Your needs:

http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top