【问题标题】:Background Image Rounded Corners背景图像圆角
【发布时间】:2012-06-16 17:39:57
【问题描述】:

我有一个改变的背景图像,在它上面我使用圆角。有没有办法隐藏图像的角落。下面是我的小部件的屏幕截图,其中显示了角落。

编辑代码:

Bitmap bm1 = BitmapFactory.decodeResource(context.getResources(), Utilities.getDrawableId(ACCUWX.Icons.AL_WIDGETBG_ICON_MAP[Integer.parseInt(wdm.iconCode)]));
Bitmap roundedBm = Utilities.getRoundedCornerBitmap(bm1);
toRet.setImageViewBitmap(R.id.widget_bg, roundedBm);

方法调用:

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(output);

        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        final RectF rectF = new RectF(rect);
        final float roundPx = 12;

        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);

        return output;
      }

为了表明我有一个背景图像和顶部的圆角,由可绘制的 xml 形状制成:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget_bg_rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="true">
    <ImageView
        android:id="@+id/widget_bg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/al_widgetbg_06_07_08"
        android:scaleType="center" />

    <LinearLayout 
        android:id="@+id/current_layout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:weightSum="8">
        <RelativeLayout
            android:id="@+id/city_time_rl"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2.5"
            android:background="@drawable/rounded_corners_top"
            android:clipChildren="true">
            <TextView
                android:id="@+id/city" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="MECHANICSBURG"
                android:textSize="16dp"
                android:textColor="@color/dk_blue"
                />

【问题讨论】:

  • 我希望问题出在 R.id.widget_bg 中,如果这种布局意味着它也是一个圆角。
  • widget_bg 是我加载可能是 15 个图像之一的图像资源的位置。它们都是矩形的。

标签: android android-layout


【解决方案1】:

您应该能够通过在背景上绘制圆角矩形之前使背景透明来完成此操作。

【讨论】:

  • 当不圆角是图像的一部分时,如何使其透明?它们是您在小部件中心看到的图像的一部分,我已将圆角放在顶部和底部。
  • 如果是这种情况,你就不能做你想做的事。
猜你喜欢
  • 1970-01-01
  • 2011-03-22
  • 2014-05-11
  • 2020-05-11
  • 2017-01-14
  • 2016-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多