とあるViewから見て、同じ階層にある近くの他のViewとの間隔を決める場合や、親のViewの境界線との間隔を決める場合、layout_margin~を使う・・・。
ViewGroup.MarginLayoutParams | Android Developers
今回はlayout_marginTopで、上との間隔だけセットする・・・。
strings.xmlで、
このようにして、
最初は、
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#f00" android:text="@string/textview1_text" /> </LinearLayout>
layout_marginTopを設定せずに赤い背景のTextViewを置いてみる・・・。
マージンがないので、左上にぴったりくっついている・・・。
そこで、
今度は、layout_marginTopに100dpをセットすると、
このように上との間隔がだいぶ空く・・・。
この間隔がちょうど100dpになっているのである・・・。
このように、layout_margin~を使って、Viewの間隔や位置を調整できる・・・。