ウェブアプリケーション,インジェクション,コマンドインジェクション

Androidアプリ開発 Viewをつかったインターフェースデザイン

Viewの位置取りのためにRelativeLayoutを使う

Using RelativeLayout for View Positioning

RelativeLayoutのViewGroupは、どのようにchild viewを
お互いに関連させて配置させるかを指定できるものです。
以下のコードでどのようにRelativeLayout使うかを示します。
以下の様なコードがactivity_main.xmlファイルにあるとします。

<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" >

   <TextView
     android:id="@+id/lblComments"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Comments"
     android:layout_alignParentTop="true"
     android:layout_alignParentLeft="true" />

   <EditText
     android:id="@+id/txtComments"
     android:layout_width="match_parent"
     android:layout_height="170dp"
     android:textSize="18sp"
     android:layout_alignLeft="@+id/lblComments"
     android:layout_below="@+id/lblComments"
     android:layout_centerHorizontal="true" />

   <Button
     android:id="@+id/btnSave"
     android:layout_width="125dp"
     android:layout_height="wrap_content"
     android:text="Save"
     android:layout_below="@+id/txtComments"
     android:layout_alignRight="@+id/txtComments" />

   <Button
     android:id="@+id/vtnCancel"
     android:layout_width="124dp"
     android:layout_height="wrap_content"
     android:text="cancel"
     android:layout_below="@+id/txtComments"
     android:layout_alignLeft="@+id/txtComments" />
<RlativeLayout>

それぞれのViewが他のViewと整列できるようにするRelativeLayoutに
ある属性に組み込まれていることに注目ください。
RelativeLayoutに組み込まれている属性は
●layout_alignParentTop
●layout_alignParentLeft
●layout_alignLeft
●layout_alignRight
●layout_below
●layout_centerHorizontalがあります。
これらそれぞれの属性の値は、参照しているViewへのIDになります。

ホーム
便利堂ロゴ
inserted by FC2 system