facebook twitter hatena line google mixi email

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

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

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");
    }
});