android - ImageView that is a fixed size, regardless of image size -
i have imageview want same size. if image smaller view, i'd centred in view. if image larger view i'd scaled down - aspect ratio preserved.
i've had several attempts @ myself - latest of is:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <imageview android:id="@+id/itemimage" android:layout_width="100dp" android:layout_height="100dp" android:scaletype="fitcenter" android:adjustviewbounds="true" android:gravity="center" android:padding="10px" /> <textview android:id="@+id/currentlentitem" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10px"/> </linearlayout>
what missing here?
try using scale type centerinside
, below:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" > <imageview android:id="@+id/itemimage" android:layout_width="100dp" android:layout_height="100dp" android:layout_alignparentright="true" android:scaletype="centerinside" android:gravity="right|center_vertical" android:padding="10px" /> <textview android:id="@+id/currentlentitem" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_toleftof="@id/list_image" android:padding="10px" /> </relativelayout>
this causes image scale down if larger layout, , scale proportionally (whereas fitxy scales without regard aspect ratio). center image if smaller.
edit: i've updated example you're wanting. here's gist of changed:
• imageview gravity changed right|center_vertical
. since want them align on right, using gravity allow if portrait orientation images.
• imageview aligned right of relativelayout
• relativelayout set wrap_content
since it's used listview.
• textview added, aligned parent's left, right edge defined left edge of itemimage.
Comments
Post a Comment