質問は、下部を除いて線形レイアウトの周りに境界線を追加する方法ですか? 私の質問に部分的に答えますが、角を丸くする方法がわかりません..
3 に答える
0
これは、使用できるカスタム Drawable です。
class RoundedImageDrawable extends Drawable {
private Bitmap mBitmap;
private Matrix mMatrix;
private Path mPath;
private float mRx;
private float mRy;
public RoundedImageDrawable(Resources res , int id, float rx, float ry) {
mBitmap = BitmapFactory.decodeResource(res, id);
mMatrix = new Matrix();
mPath = new Path();
mRx = rx;
mRy = ry;
}
@Override
protected void onBoundsChange(Rect bounds) {
RectF src = new RectF(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
RectF dst = new RectF(bounds);
mMatrix.setRectToRect(src, dst, Matrix.ScaleToFit.FILL);
mPath.addRoundRect(dst, mRx, mRy, Direction.CW);
}
@Override
public void draw(Canvas canvas) {
canvas.save();
canvas.clipPath(mPath);
canvas.drawBitmap(mBitmap, mMatrix, null);
canvas.restore();
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter cf) {
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
}
あなたのアクティビティでそれを使用してください:
LinearLayout ll = findViewById(R.id.layout);
Drawable d = new RoundedImageDrawable(getResources(), R.drawable.background, 20, 20);
ll.setBackgroundDrawable(d);
于 2013-05-28T07:58:23.317 に答える