|
|
行5: |
行5: |
| | | |
| 参考:http://tande.jp/lab/2013/01/1962 | | 参考:http://tande.jp/lab/2013/01/1962 |
− |
| |
− |
| |
− | ==レイアウト追加==
| |
− | 右下にボタン追加
| |
− | int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
| |
− | int MP = ViewGroup.LayoutParams.MATCH_PARENT;
| |
− | RelativeLayout btnLayout = new RelativeLayout(mContext);
| |
− | btnLayout.setLayoutParams(new RelativeLayout.LayoutParams(MP, MP));
| |
− | RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(WC, WC);
| |
− | lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
| |
− | lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
| |
− | Button button = new Button(this);
| |
− | playButton.setText("play");
| |
− | btnLayout.addView(playButton, lp);
| |
− | addView(btnLayout);
| |
− |
| |
− | ===他レイアウトに上の項目のボタンをかぶせる場合===
| |
− | FrameLayout frameLayout = new FrameLayout(this);
| |
− | setContentView(frameLayout);
| |
− | frameLayout.addView(otherLayout);
| |
− | // 上の項目のコードをここへ入れる
| |
− | - addView(btnLayout
| |
− | + frameLayout.addView(btnLayout); // ここを切り替える
| |
− |
| |
− | 後にaddViewしたものがz軸は手前表示となる
| |
− |
| |
− |
| |
− | ==addViewをsetLayoutParams&addViewに分ける==
| |
− | RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(WC, WC);
| |
− | btnLayout.addView(playButton, lp);
| |
− | ↓
| |
− | RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(WC, WC);
| |
− | playButton.setLayoutParams(lp);
| |
− | btnLayout.addView(playButton);
| |
− | 同じ意味になる
| |