问题
I'm trying to get my imageview with a drawable png to fill the display (I don't care about ratios). However, fill_parent doesn't work, and as far as I know there are no background to be set to a RelativeLayout?
Regards
RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:onClick="toggleAdvice"
ImageView
android:id="@+id/advice_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/pratbubbla_gron"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
回答1:
I used to stretch/shring ImageView programmatically, probably this piece of code will help you:
ImageView imageView=new ImageView(context);
imageView.setAdjustViewBounds(true);
imageView.setImageBitmap(bitmap);
imageView.setMaxHeight(maxHeight);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
layout.addView(imageView);
回答2:
All View types have android:background, including RelativeLayout. No need for an ImageView, although I can't see any reason for your one to not fill the parent.
回答3:
to do it in code use: yourImageView.setScaleType(ImageView.ScaleType.FIT_XY);
来源:https://stackoverflow.com/questions/4335206/android-imageview-stretch