Dorian Dorian - 22 days ago 6
Android Question

Android Table Row Image dimension

I want to put one image on the beginning of each row in my application . The problem is, the image is too big and when I put it there, it occupies the whole screen.

main.xml :

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="vertical"
>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/tableView"
android:layout_height="fill_parent"
android:layout_weight=".90"
android:stretchColumns="1"
></TableLayout>
</ScrollView>


This is how I add the image :

TableLayout tableView = (TableLayout) findViewById(R.id.tableView);
TableRow row = new TableRow(this);
ImageView im;
im = new ImageView(this);
im.setImageResource(R.drawable.rss);
row.addView(im);
tableView.addView(row, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));


I add the rows dynamically so, I want to add the image the same way.

PS: There is no change if I replace

TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));


with

TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));


I would like to make the image much smaller. Could you help me out?

Answer

add the imageview this way..

im.setScaleType(ImageView.ScaleType.CENTER_CROP );
row.addView(im, new TableRow.LayoutParams(width, height));