android頁面配置[之軟科技]

來源:互聯網
上載者:User

對於android系統布局方式有以下幾種:

1、LinearLayout -線性布局

  是頁面中的所有組建都是按照線性布局,

  縱向:   

  android:orientation="vertical" 表示組建垂直排成一列;

  橫向水平:

   android:orientation="horizontal"

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
 <TextView 
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:text="@string/mobile"
     android:id="@+id/mobilelable"
     />
 <EditText
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/mobilenumer"
  />
 <TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/smslable"
  android:id="@+id/smslable"
  />
 <EditText
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:minLines="3"
  android:id="@+id/messages"
 />
 <Button
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="@string/send_button"
  android:id="@+id/sms_button"
  />
</LinearLayout>

 


 

 

2、AbsoluteLayout - 絕對布局

該布局方式:

1)給每個組建都要定義id,如一個組建:android:id="@+id/linearlayout"

2)例如另一個組建要位於該組建的下方則在組建中:android:layout_below="@id/linearlayout"

3)位於父控制項的右側:android:layout_alignParentRight="true"

還有其他的一些用法,如:位於父控制項的左側等等。

 

其實android布局方式就和Html中table布局類似,也可以布局嵌套,標籤嵌套。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <LinearLayout
     android:orientation="horizontal"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:id="@+id/linearlayout"
     >
  <TextView 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textSize="18sp"
      android:text="@string/mobile"
      android:id="@+id/mobilelable"
      />
  <EditText
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_toRightOf="@id/mobilelable"
   android:id="@+id/mobilenumer"
   />
 </LinearLayout>
 <TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_below="@id/linearlayout"
  android:textSize="18sp"
  android:text="@string/smslable"
  android:id="@+id/smslable"
  />
 <EditText
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_below="@id/smslable"
  android:minLines="3"
  android:id="@+id/messages"
 />
 <Button
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_below="@id/messages"
  android:layout_alignParentRight="true"
  android:text="@string/send_button"
  android:id="@+id/sms_button"
  />
</RelativeLayout>

 


 

3、RelativeLayout(相對布局)

4、TableLayout(表格版面配置)、FrameLayout(幀布局)等

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.