How to add views dynamically to a RelativeLayout already declared in the xml layout?
How to programmatically set the layout_align_parent_right attribute of a Button in Relative Layout?
private void addPageTurnButton() { | |
View view = getLayoutInflater().inflate(R.layout.widget_page_turn, null); | |
/* | |
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( | |
RelativeLayout.LayoutParams.WRAP_CONTENT, | |
RelativeLayout.LayoutParams.WRAP_CONTENT); | |
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); | |
view.setLayoutParams(params); | |
RelativeLayout rootLayout = (RelativeLayout) findViewById(R.id.rootLayout); | |
rootLayout.addView(view); | |
*/ | |
// android.support.v7.widget.ContentFrameLayout cannot be cast to android.widget.RelativeLayout | |
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( | |
FrameLayout.LayoutParams.WRAP_CONTENT, | |
FrameLayout.LayoutParams.WRAP_CONTENT); | |
params.gravity = Gravity.RIGHT; | |
view.setLayoutParams(params); | |
view.bringToFront(); | |
FrameLayout rootLayout = (FrameLayout) findViewById(R.id.contentFragmentContainer); | |
rootLayout.addView(view); | |
Button pageUpButton = (Button) view.findViewById(R.id.widgetPageUp); | |
pageUpButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
} | |
}); | |
Button pageDownButton = (Button) view.findViewById(R.id.widgetPageDown); | |
pageDownButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
} | |
}); | |
} |