gpt4 book ai didi

java - 安卓 : Adding bottom border to relativeLayout programatically?

转载 作者:行者123 更新时间:2023-12-01 12:52:53 27 4
gpt4 key购买 nike

任何人都可以解释如何以编程方式向相对布局添加底部边框吗?
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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com