圆形DialogFrament

时间:2015-10-29 17:02:53

标签: android android-fragments android-viewpager android-dialogfragment

我需要带有圆角的DialogFragment内的ViewPager。我尝试创建自定义ViewPager。这是我的onDraw方法:

int mArcRadius = 2 * Math.round(context.getResources().getDimension(R.dimen.round_radius));
        Path mCornerPath = new Path();
        Paint mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        mCornerPath.moveTo(0,canvas.getHeight());
        RectF rectLeftCorner = new RectF(0, canvas.getHeight() - mArcRadius, mArcRadius, canvas.getHeight());
        mCornerPath.arcTo(rectLeftCorner, 90, 90);
        RectF rectRightCorner = new RectF(canvas.getWidth() - mArcRadius, canvas.getHeight() - mArcRadius, canvas.getWidth(), canvas.getHeight());
        mCornerPath.moveTo(canvas.getWidth(), canvas.getHeight());
        mCornerPath.arcTo(rectRightCorner, 0, 90);
        mCornerPath.close();
        canvas.drawPath(mCornerPath, mPaint);

但它不起作用。 ViewPage片段位于ViewPager上方。然后我尝试以相同的方式创建自定义片段布局。如果我不滑动片段,它就可以工作。 否则就会发生这样的事情 enter image description here

如何解决我的问题?

1 个答案:

答案 0 :(得分:1)

使用我使用的方法:

背景Drawable可以对齐对话框:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item> 
        <shape 
            android:shape="rectangle">
            <solid android:color="@color/transparent_black" />
            <corners android:radius="@dimen/border_radius"/>
        </shape>
    </item>   
    <item 
        android:left="@dimen/border_width" 
        android:right="@dimen/border_width"  
        android:top="@dimen/border_width"
        android:bottom="@dimen/border_width" >  

        <shape android:shape="rectangle"> 
            <solid android:color="@color/blue" />
            <corners android:radius="@dimen/border_radius"/>
        </shape>
    </item>    
</layer-list>

在xml(do self)中根据需要布局对话框。

Java代码:

 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);

            View child = getLayoutInflater().inflate(R.layout.dialog_custom_tom, null);
            alertDialogBuilder.setView(child);

            AlertDialog alertDialog = alertDialogBuilder.create();

            alertDialog.show();

alertDialogBuilder.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));