Android-absolute-layout
Androidの絶対レイアウト
'_絶対レイアウトでは、子の正確な位置(x/y座標)を指定できます。 絶対レイアウトは、絶対配置のない他のタイプのレイアウトよりも柔軟性が低く、維持が困難です。_
絶対レイアウト
AbsoluteLayoutの属性
以下は、AbsoluteLayoutに固有の重要な属性です-
Sr.No | Attribute & Description |
---|---|
1 |
android:id これは、レイアウトを一意に識別するIDです。 |
2 |
android:layout_x これは、ビューのx座標を指定します。 |
3 |
android:layout_y これは、ビューのy座標を指定します。 |
パブリックコンストラクター
AbsoluteLayout(Context context) | AbsoluteLayout(Context context, AttributeSet attrs) | AbsoluteLayout(Context context, AttributeSet attrs, int defStyleAttr) | AbsoluteLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) |
例
この例では、絶対レイアウトを使用して独自のAndroidアプリケーションを作成する方法を示す簡単な手順を紹介します。 _Hello World Example_の章で作成したAndroidアプリケーションを変更するには、次の手順に従います-
Step | Description |
---|---|
1 | You will use Android studio IDE to create an Android application and name it as demo under a package com.example.demo as explained in the Hello World Example chapter. |
2 | Modify the default content of res/layout/activity_main.xml file to include few widgets in absolute layout. |
3 | No need to modify string.xml, Android studio takes care of default constants |
4 | Run the application to launch Android emulator and verify the result of the changes done in the application. |
以下は、変更されたメインアクティビティファイル src/com.example.demo/MainActivity.java の内容です。 このファイルには、基本的な各ライフサイクルメソッドを含めることができます。
以下は res/layout/activity_main.xml ファイルの内容です-
以下は、2つの新しい定数を定義する res/values/strings.xml の内容です-
変更したばかりの* Hello World!アプリケーションを実行してみましょう。 環境設定中に *AVD を作成したと思います。 Android Studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[画像を実行:/android/images/eclipse_run.jpg [Eclipse Run Icon]アイコンをクリックします。 Android StudioはAVDにアプリをインストールして起動し、セットアップとアプリケーションで問題がなければ、次のエミュレータウィンドウが表示されます-