Android:带位图的对话框背景,带边框的圆角

Android:带位图的对话框背景,带边框的圆角,android,layout,background,dialog,Android,Layout,Background,Dialog,在一个对话框中,我希望它有一个背景,有3dp绿色的圆角边框。我已实施以下措施: 对话 ..... 布局\u圆角\u角落\u image.xml 问题: 该对话框现在没有显示任何图像(条带1),只是有一个黑色(空白)背景和3dp绿色圆角边框 图像如何成为对话框的背景,其角在绿色圆角边框内进行调整 谢谢 它通过创建一个新类来工作,编码如下: 新类别: 然后在layout.xml中,将ImageView替换为RoundedImageView: 编写主要活动的代码,说明如何实现对话框Refer

在一个对话框中,我希望它有一个背景,有3dp绿色的圆角边框。我已实施以下措施:

对话

.....
布局\u圆角\u角落\u image.xml

问题: 该对话框现在没有显示任何图像(条带1),只是有一个黑色(空白)背景和3dp绿色圆角边框

图像如何成为对话框的背景,其角在绿色圆角边框内进行调整


谢谢

它通过创建一个新类来工作,编码如下:

新类别: 然后在layout.xml中,将ImageView替换为RoundedImageView:


编写主要活动的代码,说明如何实现对话框Refere Stack Overflow问题
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="30dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="30dp"
    android:background="@drawable/layout_round_corners_image"
    android:splitMotionEvents="false" >
    .....
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:drawable="@drawable/strip1">
        <shape
            android:shape="rectangle" >
            <solid android:color="@android:color/transparent" />

            <stroke
                android:width="3dp"
                android:color="@color/green" />

            <corners android:radius="35px" />

            <padding
                android:bottom="0dp"
                android:left="0dp"
                android:right="0dp"
                android:top="0dp" />
        </shape>
    </item>

</layer-list>
public class RoundedImageView extends ImageView {

      public RoundedImageView(Context context) {
           super(context);
      }

      public RoundedImageView(Context context, AttributeSet attrs) {
           super(context, attrs);
      }

      public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
           super(context, attrs, defStyle);
      }


      @Override
      protected void onDraw(Canvas canvas) {
           int radius = (int) getResources().getDimension(R.dimen.corner_radius); // angle of round corners
           Path clipPath = new Path();
           RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight());
           clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW);
           canvas.clipPath(clipPath);
           super.onDraw(canvas);
       }
    }
    <com.example.abc.RoundedImageView
        android:id="@+id/bgd_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_margin="@dimen/dp2"
        android:scaleType="fitXY"
        android:src="@drawable/strip1" />