Reputation: 6972
I have problem to make TableRow and ImageView height to be equal to ImageView scr drawable height.
Could somebody helps me to fix this?
<?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:stretchColumns="*">
<TableRow android:gravity="top" android:layout_weight="1" >
<TextView android:text="Some text"
android:id="@+id/textView1" android:gravity="top"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</TableRow>
<TableRow android:gravity="top|center" >
<ImageView android:id="@+id/imageView1"
android:layout_height="wrap_content" android:src="@drawable/burger_king_image"
android:layout_width="wrap_content" />
</TableRow>
</TableLayout>
Upvotes: 0
Views: 2277
Reputation: 36289
I have not tested this, however it looks like ImageView has an option setAdjustViewBounds that may do everything you need:
ImageView imageview = (ImageView) findViewById(R.id.imageView1);
imageView.setAdjustViewBounds(true);
If this is not enough, you can get the drawable's height with something like this:
Drawable image = getResources().getDrawable(R.drawable.burger_king_image);
int height = image.getIntrinsicHeight();
Then you can set the size of your ImageView like so (assuming the content view has already been set to this resource):
ImageView imageview = (ImageView) findViewById(R.id.imageView1);
imageView.setMaxHeight(height);
imageView.setAdjustViewBounds(true);
Hope this helps.
Upvotes: 2