LinearLayout:線形レイアウト
一般に、多くのコントロールをインターフェイスにリストする必要がある場合、LinearLayoutを使用できます。 LinearLayoutは、子要素を垂直または水平に順番に並べ替えることです。各子要素は、前の要素の後に配置されます。以下で簡単に理解しましょう。
XMLレイアウトファイルでは、次のユニットに遭遇します
PX:画面DPのピクセルポイント:密度に基づく抽象ユニットです。画面SPの物理サイズ:DPに似ていますが、ユーザーのフォントサイズに応じてスケーリングされます
XMLコードは次のとおりです。垂直方向Androidを変更します:Orientation = "Vertical"( Vertical )
<?xml version = "1.0" encoding = "utf-8"?> <linearlayout xmlns:android = "http://schemas.android.com/apk/res/android" xmlns:ツール= "http://schemas.android. android:layout_height = "match_parent" android:android = "Vertical" Tools:context = "com.example.administrator.adapter.mainactivity"> <textView android: "First TextView" Android:background = "#ef0808" Android:layout_width = "match_parent" android:layout_height = "100dp" /> <textview android:text = "android:ravity =" center "android ="#31ef0b "android:textsize =" 18sp "android Android:layout_height = "100dp" /> <textView android:text = "third textView" android:android "android:" 18sp "android:background ="#ec07ca "android:layout_width =" match_height = "100dp" /<dp " textView "android:android =" center "android:textsize =" 18sp "android:background ="#f5d105 "android:layout_width =" match_parent "android:layout_height =" 100dp " /> < /linearlayout>
実行結果:各TextViewは上から下に配置されます。
XMLコードは次のとおりです。水平方向Androidを変更する:Orientation = "Horizontal"(水平)
<?xml version = "1.0" encoding = "utf-8"?> <linearlayout xmlns:android = "http://schemas.android.com/apk/res/android" xmlns:ツール= "http://schemas.android. Android:layout_height = "match_parent" android:android = "Horizontal" Tools:context = "com.example.administrator.adapter.mainactivity"> <textView android: "First TextView" Android:background = "#ef0808" Android:layout_width = "100dp" android:layout_height = "100dp" /> <textView android:text = "second textView" android:avhidity = "center" android = "#31EF0B" android:textsize = "18sp" android_width = "100dp" android /> <TextView Android:Text = "Third TextView" Android:Android = "Center" Android:TextSize = "18SP" Android:background = "#EC07CA" Android = "100dp" Android:layout_height = "100dp" /> textview android: "4番目のテキスト: Android:textsize = "18sp" android:background = "#f5d105" android:layout_width = "100dp" android:layout_height = "100dp" /> < /linearlayout>
実行の結果:各テキストビューは、左から右に水平に配置されます。
これら2つの線形レイアウトの唯一の違いは、Androidの値の違いです。
実験の概要:これら2つの線形レイアウトの唯一の違いは、Android:Orientationの値が異なることです。この実験を通じて、Androidの線形レイアウトを予備的に理解しています。
上記はこの記事のすべての内容です。この記事の内容が、すべての人の勉強や仕事に役立つことを願っています。また、wulin.comをもっとサポートしたいと思っています!