Reputation: 10824
Can anyone explain how to add bottom border to relative layout programatically?
PS : I'm using below code for adding border to relative layout:
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);
above code adds border for all corners but I want to add border just for bottom.
Is there any way or equivalent way to do that?
Upvotes: 0
Views: 1347
Reputation: 2467
You can add a View to your relative layout:
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);
Upvotes: 1