lundi 20 avril 2015

Android image scale to Listview items

I am setting up a ListView that should hold rows, with an image thumbnail and text. I would like to show 5 rows on the screen, and scale the images to the available space depending on the device.

I have made the following layout xml files. First one holds the ListView, and the second the list item. I am currently setting a fixed size. How could I change the layout to scale images to adapt to the screen size?

Setting up the ListView:

<FrameLayout xmlns:android="http://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"" >

    <ListView
    android:id="@+id/gallery"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    </ListView>

</FrameLayout>

The list item layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
 android:layout_width="match_parent"
 android:layout_height="fill_parent"
 android:orientation="horizontal" >
 <ImageView
 android:id="@+id/icon"
 android:layout_width="50dp"
 android:layout_height="50dp"
 android:layout_marginBottom="5dp"
 android:layout_marginLeft="5dp"
 android:layout_marginRight="5dp"
 android:layout_marginTop="5dp"
 android:src="@raw/pic01" />

 <TextView
 android:id="@+id/textview"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:textSize="20sp" 
 android:paddingTop="5dp"/>

</LinearLayout>

Aucun commentaire:

Enregistrer un commentaire