安卓介面設計中屬性設定

來源:互聯網
上載者:User

標籤:

最近在學習安卓介面設計的時候,對於其中很多參數很是迷茫,於是尋找了一番之後總結如下:

第一組:

android:gravity: view組件內部內容的gravity屬性

android:layout_gravity:view組件相對於其父組件的屬性

如所示:

<?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" >    <LinearLayout        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1"        android:background="#e3e2ad"        android:orientation="vertical" >        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center_horizontal"            android:textSize="24sp"            android:text="gravity=" />        <TextView            android:layout_width="200dp"            android:layout_height="40dp"            android:background="#bcf5b1"            android:gravity="left"            android:text="left" />        <TextView            android:layout_width="200dp"            android:layout_height="40dp"            android:background="#aacaff"            android:gravity="center_horizontal"            android:text="center_horizontal" />        <TextView            android:layout_width="200dp"            android:layout_height="40dp"            android:background="#bcf5b1"            android:gravity="right"            android:text="right" />        <TextView            android:layout_width="200dp"            android:layout_height="40dp"            android:background="#aacaff"            android:gravity="center"            android:text="center" />    </LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1"        android:background="#d6c6cd"        android:orientation="vertical" >        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center_horizontal"            android:textSize="24sp"            android:text="layout_gravity=" />        <TextView            android:layout_width="200dp"            android:layout_height="40dp"            android:layout_gravity="left"            android:background="#bcf5b1"            android:text="left" />        <TextView            android:layout_width="200dp"            android:layout_height="40dp"            android:layout_gravity="center_horizontal"            android:background="#aacaff"            android:text="center_horizontal" />        <TextView            android:layout_width="200dp"            android:layout_height="40dp"            android:layout_gravity="right"            android:background="#bcf5b1"            android:text="right" />        <TextView            android:layout_width="200dp"            android:layout_height="40dp"            android:layout_gravity="center"            android:background="#aacaff"            android:text="center" />    </LinearLayout></LinearLayout>

 

注意:這個參數不要應用於RelativeLayout,可以應用於LinearLayout和FrameLayout。

        如果我們設定組件參數為wrap_content,那麼gravity的設定就沒有任何作用。同樣的,如果LinearLayout被設定為wrap_content, 那layout_gravity的設定也不會有任何作用了。

       如果LinearLayout被設定成為vertical,那麼layout_gravity=center和layout_gravity=center_horizontal,因為在垂直的線性布局中,我們不能將組件之餘垂直的中間。

 

第二組:

android:layout_width:形容本組件和父容器的關係

android:width:描述組件本身的大小

如果組件屬性設定中有layout_width屬性的話(非wrap_content),則不管有沒有width屬性,該組件的形狀都是由父容器決定的,例如:

<Button          android:id="@+id/button1"          android:layout_width="match_parent"          android:width="100dp"          android:layout_height="wrap_content"          android:layout_gravity="center"          android:gravity="right"          android:text="Bsdfsdfsdfsdfsdfsdfsdfsdf" />  

如所示,不管width設定的多小,button的寬度都是由LinearLayout控制的。

如果android:layout_width設定為“wrap_content”時,就是說view組件的寬度隨著其中內容的變化而變化,此時,如果存在width的話,那麼view的寬度就是有它們共同控制的。

<Button         android:id="@+id/button1"         android:layout_width="wrap_content"         android:width="50dp"         android:layout_height="wrap_content"         android:text="Bsdfsdfsdfsdfsdfsdfsdfsdf" />  

今天就先寫到這裡,以後如果碰到有不懂的,還會繼續更新~

安卓介面設計中屬性設定

聯繫我們

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