facebook twitter hatena line email

Android/レイアウト/サイズ変更イベント

提供: 初心者エンジニアの簡易メモ
2019年4月16日 (火) 11:35時点におけるAdmin (トーク | 投稿記録)による版

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

viewの縦横が変更された際に動作するサンプル

RelativeLayout layout = new RelativeLayout(mContext);
layout.setLayoutParams(new RelativeLayout.LayoutParams(MP, MP));
layoutParam = new RelativeLayout.LayoutParams(WC, WC);
layoutParam.addRule(RelativeLayout.CENTER_HORIZONTAL);
layoutParam.addRule(RelativeLayout.CENTER_VERTICAL);
TextView textView = new TextView(mContext);
textView.setText("hogehoge");
textView.setLayoutParams(layoutParam);
layout.addView(textView);
addView(layout);
layout.addOnLayoutChangeListener(new OnLayoutChangeListener() {
    @Override
    public void onLayoutChange(View v, int left, int top, int right, int bottom,
                               int oldLeft, int oldTop, int oldRight, int oldBottom) {
        Log.i(TAG, "TextView onLayoutChange");
    }
});