2014-03-01 179 views
0

我有一個圓形圖像,這個圓形圖像在linearlayout裏面。 我希望線性佈局也是圓形的,我怎樣才能製作線性佈局圓形? 不是採取rectentoular空間,但圓形空間?圓形線性佈局android

這對我來說非常重要,原因正在開發與圓形image..and STHG旁邊的圓形圖像STHG把它捆起來這是一個的LinearLayout以及

+0

後一個卡扣與圖像 –

+0

後快照不相信一個圓形的線性佈局是現實可行的,但描述更多移動你想要做的,和一個不同的方法(如重疊他們),可能會起作用。 – Piyush

+1

的圓形圖像 – NameSpace

回答

1

您可以創建一個圓形的位圖中的ImageView使用,在圖像周圍使用白色筆觸。

然後,您可以使用RelativeLayout將圖像放在左側,其他UI元素放在右側。

有一個關於這個功能很有趣的帖子:

http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/它由羅曼蓋伊(例如Android團隊在谷歌)編寫的。

你可以使用這樣的東西。 本示例創建一個圓形位圖,大約白色筆劃。你可以改變它,用黑線添加白色筆畫。

public class CircleDrawable extends Drawable { 

    private final BitmapShader mBitmapShader; 
    private final Paint mPaint; 
    private Paint mWhitePaint; 
    int circleCenterX; 
    int circleCenterY; 
    int mRadus; 
    private boolean mUseStroke = false; 
    private int mStrokePadding = 0; 

    public CircleDrawable(Bitmap bitmap) { 

     mBitmapShader = new BitmapShader(bitmap, 
       Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); 

     mPaint = new Paint(); 
     mPaint.setAntiAlias(true); 
     mPaint.setShader(mBitmapShader); 

    } 

    public CircleDrawable(Bitmap bitmap, boolean mUseStroke) { 
     this(bitmap); 

     if (mUseStroke) { 
      this.mUseStroke = true; 
      mStrokePadding = 4; 
      mWhitePaint = new Paint(); 
      mWhitePaint.setStyle(Paint.Style.FILL_AND_STROKE); 
      mWhitePaint.setStrokeWidth(0.75f); 
      mWhitePaint.setColor(Color.WHITE); 
     } 
    } 

    @Override 
    protected void onBoundsChange(Rect bounds) { 
     super.onBoundsChange(bounds); 
     circleCenterX = bounds.width()/2; 
     circleCenterY = bounds.height()/2; 

     if (bounds.width() >= bounds.height()) 
      mRadus = bounds.width()/2; 
     else 
      mRadus = bounds.height()/2; 
    } 

    @Override 
    public void draw(Canvas canvas) { 
     if (mUseStroke) { 
      canvas.drawCircle(circleCenterX, circleCenterY, mRadus, mWhitePaint); 
     } 
     canvas.drawCircle(circleCenterX, circleCenterY, mRadus - mStrokePadding, mPaint); 
    } 

    @Override 
    public int getOpacity() { 
     return PixelFormat.TRANSLUCENT; 
    } 

    @Override 
    public void setAlpha(int alpha) { 
     mPaint.setAlpha(alpha); 
    } 

    @Override 
    public void setColorFilter(ColorFilter cf) { 
     mPaint.setColorFilter(cf); 
    } 

    public boolean ismUseStroke() { 
     return mUseStroke; 
    } 

    public void setmUseStroke(boolean mUseStroke) { 
     this.mUseStroke = mUseStroke; 
    } 

} 

要使用它:

CircleDrawable circle = new CircleDrawable(bitmap,true); 
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) 
    imageView.setBackground(circle); 
     else 
    imageView.setBackgroundDrawable(circle);