2016-05-11 33 views

回答

0

在你的.xml頁面使用此代碼:

<com.xxx.xxx.xxx.RoundedImageView 
        android:id="@+id/imageView_round" 
        android:layout_width="60dp" 
        android:layout_height="60dp" 
        android:layout_gravity="center" 
        android:layout_marginTop="10dp" 
        android:layout_weight="1" 
        android:scaleType="fitCenter" 
        android:src="@drawable/doctor" /> 

對於RoundedImageView你必須複製粘貼此:

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); 
    } 

    @SuppressLint("DrawAllocation") 
    @Override 
    protected void onDraw(Canvas canvas) { 

     Drawable drawable = getDrawable(); 

     if (drawable == null) { 
      return; 
     } 

     if (getWidth() == 0 || getHeight() == 0) { 
      return; 
     } 
     Bitmap b = ((BitmapDrawable) drawable).getBitmap(); 
     Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true); 
     int w = getWidth(), h = getHeight(); 

     Bitmap bmm = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(), 
       bitmap.getHeight(), true); 

     Bitmap roundBitmap = getCroppedBitmap(bitmap, w); 
     canvas.drawBitmap(roundBitmap, 0, 0, null); 

    } 

    public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) { 
     Bitmap sbmp; 
     if (bmp.getWidth() != radius || bmp.getHeight() != radius) 
      sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false); 
     else 
      sbmp = bmp; 
     Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), 
       Config.ARGB_8888); 
     Canvas canvas = new Canvas(output); 

     final int color = 0xffa19774; 
     final Paint paint = new Paint(); 
     final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight()); 

     paint.setAnti`enter code here`Alias(true); 
     paint.setFilterBitmap(true); 
     paint.setDither(true); 
     canvas.drawARGB(0, 0, 0, 0); 
     paint.setColor(Color.parseColor("#BAB399")); 
     canvas.drawCircle(sbmp.getWidth()/2 + 0.7f, 
       sbmp.getHeight()/2 + 0.7f, sbmp.getWidth()/2 + 0.1f, paint); 
     paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); 
     canvas.drawBitmap(sbmp, rect, rect, paint); 

     return output; 
    } 

} 

我希望這將有助於

0

這可以通過回收站視圖來實現的,如果你要滾動的圖像,以及,水平滾動回收站視圖中,可以使用下面的代碼。

recyclerView.setLayoutManager(new LinearLayoutManager(RecyclerView_Activity.this, LinearLayoutManager.HORIZONTAL, false)); 

你可以在一個水平佈局添加回收站視圖(圖像)的TextView(有值+194共享),一旦我們滾動列表上可以設置待發元素在TextView的數。

如果您的要求不是滾動圖像,那麼您可以簡單地在線性佈局中添加圖像,並添加文本視圖來顯示計數。