Android: programmatically align parent snapshot + bottom edge

How can I programmatically add a RelativeLayout that is aligned to the bottom of the parent element and add a marker or pad in the same RelativeLayout?

Example:

enter image description here

+8
android android-layout relativelayout
source share
2 answers

Here's how you can do it:

// Get the parent layout RelativeLayout parent = (RelativeLayout) findViewById(R.id.parent); // Create your custom layout RelativeLayout relativeLayout = new RelativeLayout(this); // Create LayoutParams for it // Note 200 200 is width, height in pixels RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(200, 200); // Align bottom-right, and add bottom-margin params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); params.bottomMargin = 100; relativeLayout.setLayoutParams(params); relativeLayout.setBackgroundColor(Color.BLUE); // Add the custom layout to your parent layout parent.addView(relativeLayout); 
+30
source share

you can try this, it works in my case:

 RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) view.getLayoutParams(); // position on right bottom rlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0); rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP,0); rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
+1
source share

All Articles