Android開發中XML布局的常用屬性說明,android開發xml布局

來源:互聯網
上載者:User

Android開發中XML布局的常用屬性說明,android開發xml布局

 <!--    常用屬性說明:     android:id="@+id/button"  為控制項指定Id     android:text="NNNNNNNNNN" 指定控制項的顯示文本     android:textSize="12pt"   讓控制項中的文字顯示尺寸     android:singleLine="true"  讓控制項中顯示的文本在一行顯示完,顯示不了的自動省略     android:gravity="left"   讓控制項中的內容靠左顯示     android:padding="16dp" 讓控制項中的文本距控制項外邊框的填充尺寸,可以像CSS裡的padding_left...     android:background="#ff0000"  控制項中的背景顏色     android:width="1060dip" 指定控制項的寬度,好像不起作用了     android:height="200dip" 指定控制項的高度,好像不起作用了     android:layout_width="200dp"  控制項布局寬度,如果是fill_parent 表示水平填充滿父控制項     android:layout_height="wrap_content" 填充高度;fill_parent表示填滿父控制項,最好不要。     android:layout_weight="1" 表示與同級控制項的布局權重,如果就兩個都是1那就是一人一半,數字大的佔用的空間多    -->
<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"    tools:context=".MainActivity">    <LinearLayout        android:orientation="vertical"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_alignParentLeft="true"        android:layout_alignParentStart="true">        <Button            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="NNN"            android:width="160dp"            android:height="200dp"            android:background="#ff0000"            android:textSize="12pt"            android:gravity="right"            android:padding="16dp"            android:singleLine="true"            android:layout_weight="1"            android:id="@+id/button" />        <!--        android:singleLine="true"   表示單行顯示,顯示不完的省略        -->        <Button            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="New Button"            android:id="@+id/button4"            android:layout_gravity="right"            android:layout_weight="2" />    </LinearLayout></RelativeLayout>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.