閱讀766 返回首頁    go 阿裏雲 go 技術社區[雲棲]


android view視圖的層疊(疊加)

第一種情況:google android textview drawable
參考:           

setCompoundDrawable to add Drawables to TextView

http://mgmblog.com/2010/06/04/setcompounddrawable-to-add-drawables-to-textview/
上麵是給出TextView添加Drawables時調用的方法
第二種情況:
而在圖像之中想要添加文字,而又不想用一個又一個的view進行疊加怎麼辦呢
Bitmap bm = BitmapFactory.decodeResource(getResources(),R.drawable.a);
Bitmap bm1 = BitmapFactory.decodeResource(getResources(),R.drawable.b);
Bitmap bm2 = BitmapFactory.decodeResource(getResources(),R.drawable.c);
Drawable[] array=new Drawable[3];

array[0] = new BitmapDrawable(bm2);
array[1] = new BitmapDrawable(bm1); //白色
array[2] = new BitmapDrawable(mytext.getDrawingCache());
LayerDrawable la=new LayerDrawable(array);

la.setLayerInset(0, 0, 0, 0, 0);
la.setLayerInset(1, 200, 200, 200, 200);
la.setLayerInset(2, 400, 400, 400, 400);//第一個參數2代表數組的第三個元素,為位圖資源
image.setImageDrawable(la);

上麵是三個圖片的疊加並顯示在同一個view中,那麼文字和圖片如何一起疊加顯示呢?

自定義視圖時重載onDraw()函數提供了如下的函數
protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);
  canvas.drawColor(Color.WHITE);
        /*寫字*/
  paint = new Paint();
        paint.setTextSize(24);
        canvas.drawText(getResources().getString(R.string.title), 50, 50, paint);

這樣直接出來的字的字體不大好看,如何解決呢?
來自https://jayzhou215.blog.163.com/blog/static/13271353320122104532944/

最後更新:2017-04-03 14:54:03

  上一篇:go 收費係統——問題集錦(一)
  下一篇:go AfxBeginThread和CreateThread具體區別