facebook twitter hatena line email

「Android/レイアウト/マージン」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==マージンサンプル== setMarginsを使う LinearLayout layout = new LinearLayout(activity); layout.setBackgroundColor(Color.argb(128, 16, 16, 16)); LinearLayout...」)
 
(マージンサンプル)
 
(同じ利用者による、間の2版が非表示)
行10: 行10:
 
  txt.setText("0:00");
 
  txt.setText("0:00");
 
  layout.addView(txt, lp);
 
  layout.addView(txt, lp);
 +
 +
<pre>
 +
    <FrameLayout
 +
        android:layout_width="match_parent"
 +
        android:layout_height="match_parent"
 +
        android:paddingBottom="20dp"
 +
        android:paddingLeft="20dp"
 +
        android:paddingRight="20dp"
 +
        android:paddingTop="20dp"
 +
        />
 +
</pre>

2019年5月10日 (金) 17:24時点における最新版

マージンサンプル

setMarginsを使う

LinearLayout layout = new LinearLayout(activity);
layout.setBackgroundColor(Color.argb(128, 16, 16, 16));
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(WC, WC);
lp.setMargins(10, 20, 30, 40); // left, top, right, bottom
TextView txt = new TextView(activity);
txt.setTextColor(Color.WHITE);
txt.setText("0:00");
layout.addView(txt, lp);
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="20dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="20dp"
        />