Last active
September 19, 2016 08:52
-
-
Save wowiwo1/a40dfb9597ce3b6cf041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
RelativeLayout rl = new RelativeLayout(this); | |
rl.setBackgroundColor(Color.BLUE); | |
Button btn = new Button(this); | |
btn.setId(1); | |
btn.setText("Press Me"); | |
btn.setBackgroundColor(Color.YELLOW); | |
RelativeLayout.LayoutParams params_btn = new RelativeLayout.LayoutParams( | |
RelativeLayout.LayoutParams.WRAP_CONTENT, | |
RelativeLayout.LayoutParams.WRAP_CONTENT | |
); | |
params_btn.addRule(RelativeLayout.CENTER_HORIZONTAL); | |
params_btn.addRule(RelativeLayout.CENTER_VERTICAL); | |
EditText et = new EditText(this); | |
et.setId(2); | |
int _px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, | |
getResources().getDisplayMetrics()); | |
et.setWidth(_px); | |
RelativeLayout.LayoutParams params_et = new RelativeLayout.LayoutParams( | |
RelativeLayout.LayoutParams.WRAP_CONTENT, | |
RelativeLayout.LayoutParams.WRAP_CONTENT | |
); | |
params_et.addRule(RelativeLayout.ABOVE, btn.getId()); | |
params_et.addRule(RelativeLayout.CENTER_HORIZONTAL); | |
params_et.setMargins(0, 0, 0, 80); | |
rl.addView(btn, params_btn); | |
rl.addView(et, params_et); | |
setContentView(rl); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment