RelativeLayoutのいくつかのパラメータの理解
3883 ワード
個人理解:相対レイアウト:1つのオブジェクトを参照して、別のオブジェクトをこのオブジェクトの上、下、左、右、左上、左下、右上、右下などの位置に追加します.
幅に内容を含める
android:layout_width
wrap_コンテンツ幅と同じ
fill_parentは親オブジェクトと同じ幅です
android:layout_below="@+id/ok"
オブジェクトはidがokオブジェクトの下にあります
android:layout_toLeftOf="@id/ok"
オブジェクトはokオブジェクトの左側にあります
android:layout_centerHorizontal="true"
水平中央、個人的には容器の真ん中に位置合わせしていると思います
android:layout_alignLeft="@+id/ok"
idがokのオブジェクトに左揃え
paddingは塗りつぶし、marginはマージン
android:padding属性で設定可能、4方向のマージン属性はandroid:paddingLeft、android:paddingRight、android:paddingTop、and android:paddingBottom.
結論:
*android:layout_marginBottom
*android:layout_marginLeft
*android:layout_marginRight
*android:layout_marginTop
上の属性の値は、下の相対位置のオブジェクトの値に基づいて計算され、相対的なオブジェクトがなければ全体的なレイアウトで計算されます.
*android:layout_below
*android:layout_above
*android:layout_toLeftOf
*android:layout_toRightOf
*android:layout_alignTop
*android:layout_centerHrizontal//横スクリーンまたは縦スクリーンをサポートしているか
*android:layout_centerVertical//これは単語の意味によって:中心垂直
*android:layout_centerInparent //
android:layout_centerInParent=「true」//親の中央
android:layout_centerInParent="false"... ブラウザはマルチウィンドウ表示をサポートしていません.つまり、すべてのページが単一のウィンドウで開くことで、ページレイアウト制御表示の問題を回避できます.
親に対する次の相対位置
*android:layout_alignParentBottom
*android:layout_alignParentLeft
*android:layout_alignParentRight
*android:layout_alignParentTop
*android:layout_alignWithParentIfMissing
インスタンスコード:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/testBtn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="false"
android:layout_marginTop="46dp"
android:text="Button" />
<Button
android:id="@+id/activity1_btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/testBtn1"
android:layout_below="@+id/testBtn1"
android:layout_marginTop="20dp"
android:text="RadioGroupStudy" />
<Button
android:id="@+id/testBtn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/activity1_btn2"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="@string/linerlayout_test" />
</RelativeLayout>