Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 半径后图像设置不正确_Android - Fatal编程技术网

Android 半径后图像设置不正确

Android 半径后图像设置不正确,android,Android,我有一个布局,其中有两个ImageView。并在运行时在该imageView上设置拐角的半径(正常工作)。但在设置半径后,当我在ImageView(从图库中选择)上设置图像时,它会以方形显示。为什么半径不适用于我选择的图像。像这样设置运行时的半径 LayerDrawable layerDrawable = (LayerDrawable) getResources() .getDrawable(R.drawable.back_image); Grad

我有一个布局,其中有两个ImageView。并在运行时在该imageView上设置拐角的半径(正常工作)。但在设置半径后,当我在ImageView(从图库中选择)上设置图像时,它会以方形显示。为什么半径不适用于我选择的图像。像这样设置运行时的半径

LayerDrawable layerDrawable = (LayerDrawable) getResources()
                .getDrawable(R.drawable.back_image);
        GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable
                .findDrawableByLayerId(R.id.gradientDrawble);
        gradientDrawable.setCornerRadius(70);

        image1.setBackground(layerDrawable);
        image2.setBackground(layerDrawable);
back_image.xml


我想您需要具有圆角半径的imageview,这样您就可以使用

这是一个片段


试试这个简短的代码,它不需要任何库,工作起来很有魅力

RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(Activity.this.getResources(), yourbitmap);
roundedBitmapDrawable.setCornerRadius(setYourOwnRadius);
roundedBitmapDrawable.setCircular(true);
your imageview.setImageDrawable(roundedBitmapDrawable);

非常感谢。但我不想使用任何customView。您是否使用图像加载程序库在imageview中显示图像?@Divya Chavada看到我的答案,希望这能帮助您。@AndyDeveloper谢谢。但它对我不起作用。:(不,我不使用任何库@Beena@DivyaChavada使用这个RoundedBitmapDrawable时你面临什么问题?
<com.makeramen.roundedimageview.RoundedImageView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/imageView1"
    android:src="@drawable/photo1"
    android:scaleType="fitCenter"
    app:riv_corner_radius="30dip"
    app:riv_border_width="2dip"
    app:riv_border_color="#333333"
    app:riv_mutate_background="true"
    app:riv_tile_mode="repeat"
    app:riv_oval="true" />
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(Activity.this.getResources(), yourbitmap);
roundedBitmapDrawable.setCornerRadius(setYourOwnRadius);
roundedBitmapDrawable.setCircular(true);
your imageview.setImageDrawable(roundedBitmapDrawable);