ViewGroupレイアウトの高度なUIの促進(D)

その他のAndroidのビデオの高度なアーキテクチャ高度な学習クリック:https://space.bilibili.com/474380680
のLinearLayout、RelativeLayout、でframeLayout、AbsoluteLayoutから、この記事のGridLayout 共通ビューのレイアウトを紹介します:

説明A、UIプログラミング

以下のためAndroidのアプリケーション、すべてのユーザーインターフェイス要素が作られていますViewし、ViewGroupオブジェクトが構築されました。Viewユーザーと対話することができ、オブジェクトの画面上に描画されます。以下のためにViewGroup、それは保存のために、他の1であるViewViewGroup配布コンテナオブジェクト!

 
11158618-cac0e2dc292c875b.png
 

Androidそれは私たちを提供ViewViewGroup、そのような糸のレイアウト、レイアウトの相対的、絶対的なレイアウト、フレームレイアウトとして((等ボタン、イメージ、およびテキストフィールドなど)いくつかの一般的な入力コントロールを提供する二つのサブクラスのセットとレイアウトパターンの様々なテーブルレイアウトなど)。

第二に、ユーザーインターフェースのレイアウト

もしAPP各コンポーネントがユーザインタフェース上に表示されるソフトウェア、階層を使用Viewし、ViewGroupオブジェクトが構成され、例えば、それぞれがViewGroup見えコンテナではなく、各ViewGroupビューのグループは、サブビュー編成するために使用されるView容器を、そのサブビューは、Viewいくつかのコントロールまたは小ブロック領域の入力部材であってもよいですUIあなたは階層ツリーを持っている場合は、よりシンプルな階層構造は、最高のパフォーマンスに適しているため、あなたは、自分のニーズに応じて、いくつかのレイアウトを設計することができますが、それをシンプルに保つために。

レイアウトを宣言するためには、最も簡単な方法も使用することができ、コード内のオブジェクトとビルドをインスタンス化することができますxmlファイル。

<?xml version="1.0" encoding="utf-8"?>
<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/text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="TextView" />
    <Button android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
</LinearLayout>

第三に、Androidレイアウトは、いくつかの一般的なビューを提供します。

  1. LinearLayoutリニアレイアウト
  2. RelativeLayout相対レイアウト
  3. FrameLayoutフレームレイアウト
  4. AbsoluteLayout絶対レイアウト
  5. TableLayoutテーブルレイアウト
  6. GridLayoutグリッドレイアウト

第四に、重要ないくつかの記述

線形レイアウトは:
子コントロールを指す水平または垂直に配列されました。

相対レイアウトは:
子コントロールを指すコントロールまたは親コンテナの位置に対して、サブ制御装置との間の相対的な位置を。

フレームレイアウト:
サブに配置されているすべてのコントロールを指し左隅とバックは要素の前に要素の上に直接置きます。

絶対レイアウト:
絶対位置決めによって子コントロールを指し、X、Y位置にその位置が配置決定します。

テーブルレイアウトは:
行と列の形で子コントロールの配置を指し、それぞれの行があるのTableRow Viewオブジェクトまたはオブジェクト。

 
11158618-806450345dd6ffaf
画像

4.1のLinearLayoutリニアレイアウト

共通の属性:

  1. id:コンポーネントのリソースを追加しますid
  2. orientation:レイアウト配置、2つの方法があります:
    horizontal水平
    vertical垂直
  3. layout_width:レイアウト幅、wrap_contentアセンブリのための実際の幅は、match_parent親が充填された容器を示します
  4. layout_height:レイアウトの長さは、wrap_contentアセンブリの実際の長さは、表されるmatch_parent親が充填された容器を示します
  5. gravity:アライメント制御アセンブリのサブ要素が含まれています
  6. layout_gravity:親コンテナのアセンブリ内の配向を制御します
  7. background:コンポーネントの背景画像を追加

LinearLayoutグループではと、垂直水平方向またはすべての子どもの分布では、図であるandroid:orientationプロパティ。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="输入账号" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="输入密码" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登录" />
</LinearLayout>

4.2 RelativeLayout相対レイアウト

RelativeLayoutグループ相対レイアウトビュー、子の相対位置を表示するためのビュークラスは、デフォルトでは、左上隅にすべての子ビューに配布されますされています。

  1. layout_alignParentTop:以下のためのtrue上限とビュー整列親の上限
  2. layout_centerVertical:されたtrue親クラスをサブクラス中央に配置されます
  3. layout_below:リソースのビューID以下
  4. layout_toRightOf:リソースのビューIDを右に
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <EditText
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="你的名字" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/name"
        android:layout_alignParentRight="true"
        android:text="正确" />
</RelativeLayout>

4.3 GridViewグリッドレイアウト

GridView実際には、同じビューは、グリッド・コンポーネントであるViewGroup二次元ビュー。レイアウトは、アダプタを充填することができます。

 
11158618-cc5543d29b1702a6.png
 

コンポーネントの4.4 ListViewのリスト

ListViewリスト項目は、コンテンツアダプタを追加するために行うことができる、スクロール可能なリストを表示するための図です。

 
11158618-0d7d799ae329ae8d.png
 

その他のAndroidのビデオの高度なアーキテクチャ高度な学習クリック:https://space.bilibili.com/474380680
説明リンク:https://www.jianshu.com/p/58d63e31ea18

おすすめ

転載: www.cnblogs.com/Android-Alvin/p/11953041.html