任何人都可以解释如何以编程方式向相对布局添加底部边框吗?
PS:我使用下面的代码向相对布局添加边框:
RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.borderEffect);
ShapeDrawable rectShapeDrawable = new ShapeDrawable();
Paint paint = rectShapeDrawable.getPaint();
paint.setColor(Color.GRAY);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(5);
layout.setBackgroundDrawable(rectShapeDrawable);
上面的代码为所有角添加了边框,但我想只为底部添加边框。
有什么方法或等效方法可以做到这一点吗?
最佳答案
您可以将 View 添加到相对布局中:
View bottomBorder = new View(CONTEXT);
bottomBorder.setBackgroundColor(Color.GRAY);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 1);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
relativeLayout.addView(bottomBorder, params);
关于java - 安卓 : Adding bottom border to relativeLayout programatically?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24095736/