android,imageview拉伸

elw*_*wis 3 android imageview

我正在尝试使用可绘制的png来获取我的imageview以填充显示(我不关心比率).但是,fill_parent不起作用,据我所知,没有背景设置为RelativeLayout?

问候

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"
Run Code Online (Sandbox Code Playgroud)

Reu*_*ton 8

所有视图类型都android:background包括RelativeLayout.不需要一个ImageView,虽然我看不出任何理由让你的人不填补父母.


Bar*_*ica 8

我以编程方式拉伸/剪切ImageView,可能这段代码可以帮助你:

    ImageView imageView=new ImageView(context);
    imageView.setAdjustViewBounds(true);
    imageView.setImageBitmap(bitmap);
    imageView.setMaxHeight(maxHeight);
    imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    layout.addView(imageView);
Run Code Online (Sandbox Code Playgroud)