所以问题How to add border around linear layout except at the bottom?回答我的问题部分,但我似乎无法弄清楚如何使边角圆..圆形边框LinerLayout
回答
创建布局文件夹命名为
round_border
一个XML文件。现在把这个代码在XML文件中:
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <stroke android:width="4dp" android:color="#FF00FF00" /> <solid android:color="#ffffff" /> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:radius="10dp" />
现在使用这个文件作为
LinearLayout
的这样一个背景:<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="20dip" android:background="@drawable/round_border">
只是一个问题我的应用程序有一个背景图像无论如何只是让边界被看到? –
@JacobAnthonyTonna你在寻找圆角的图像吗? – Raghunandan
@JacobAnthonyTonna我不认为你可以设置线性布局。我猜你正在寻找具有圆角的图像 – Raghunandan
在您的线性布局
android:background="@drawable/bkg"
定义如下XML中可绘制夹。
bkg.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#10EB0A"/>
<stroke android:width="3dp"
android:color="#0FECFF" />
<padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
这是一个自定义绘制,你可以使用:
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);
- 1. LimeJS圆形边框
- 2. Android的圆形边框圆形图像
- 3. 地图圆形边框webkit
- 4. 倒圆形的边框css
- 5. 圆形边框进度条
- 6. 完美的圆形边框
- 7. 切割圆形边框Swift
- 8. css3圆形边框奇怪
- 9. 使六边形形状的边框,圆角和透明背景
- 10. 带有圆形边框的Android桌面
- 11. 使图像完全无边框圆形
- 12. 在JavaFX矩形边框画圆圈
- 13. 制作带边框的圆形按钮
- 14. jquery的圆形插件+边框
- 15. AllowTransparency替代圆角边框形式
- 16. 集中了一个圆形边框
- 17. 圆形边框与间距悬停
- 18. 圆形元素的纯色边框
- 19. CSS圆形边框填充动画
- 20. 圆形边框不能在铬工作
- 21. 沿着圆角矩形的UIButton边框
- 22. 如何向jradiobutton添加圆形边框
- 23. JavaScript图片缩放 - 圆形边框
- 24. 没有边框的圆角矩形UIButton
- 25. 圆形图像或边框半径100%?
- 26. 将边框添加到圆形图像
- 27. 将边框添加到圆形图像
- 28. 使imagemagick中的图像圆形边框
- 29. Safari中的透明圆形边框
- 30. 渐变圆形边框和显示:块
你试试这个:http://stackoverflow.com/q/6514114/ 693752? – Snicolas