2012-06-13 144 views
1

我有一個背景圖像,它在上面改變,我使用圓角。有沒有辦法隱藏圖像的角落。以下是顯示角落的小部件的屏幕截圖。 enter image description here背景圖像圓形角落

編輯代碼:

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" 
       /> 
+0

什麼是R.id.widget_bg? – Aerrow

+0

我希望這個問題出現在R.id.widget_bg中,如果這個佈局意味着這個也是一個圓角。 – Aerrow

+0

widget_bg是我加載可能是15張圖像之一的圖像資源的地方。它們都是矩形的。 – taraloca

回答

0

你應該可以做到這一點通過使背景透明,然後在其頂部繪製圓角矩形。

+0

未接地的角落是否是圖像的一部分時,我怎樣才能讓它透明?它們是您在小部件中心顯示的圖像的一部分,我已將頂部和底部的圓角放置在頂部。 – taraloca

+0

如果是這種情況,你不能做你想做的事情。 – matt5784