Android布局總結和Android 9 patch 圖片使用

來源:互聯網
上載者:User

一、布局的一些問題總結     

1、首先說下RelativeLayout布局,其實實現的效果就是按照元素的相對位置設定擺放位置,如果沒有設定相關屬性,例如above、belove等相關屬性是預設是在螢幕的頂部,並且多個View互相疊放,後面的View會疊放在前面的View之上。根據這個特點,我們可以設定一下進度條之類的東東,比如下面的一個瀏覽器對話方塊,當訪問網頁是彈出對話方塊,網頁結束是將對話方塊的view設定gone即可。

<?xml version="1.0" encoding="utf-8"?><AbsoluteLayoutandroid:id="@+id/webfrm"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@color/bgcolor"android:orientation="vertical"xmlns:android="http://schemas.android.com/apk/res/android"><WebViewandroid:id="@+id/webview1"android:layout_width="fill_parent"android:layout_height="fill_parent"></WebView><RelativeLayoutandroid:id="@+id/RelativeLayout01"android:layout_width="fill_parent"android:layout_height="fill_parent"><ProgressBarandroid:id="@+id/LoadingBar"android:indeterminate="true"android:visibility="visible"android:layout_centerInParent="true"android:minHeight="100px"android:minWidth="100px"android:layout_height="100px"android:layout_width="100px" /></RelativeLayout></AbsoluteLayout>

預覽:


2、FrameLayout的一些使用心得,之前項目中用的比較少,對她得認識也不深。

      Framlayout可以用來實現多種介面的切換。在TabHost中經常用到。

   

<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@android:id/tabhost"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <LinearLayout        android:orientation="vertical"        android:layout_width="fill_parent"        android:layout_height="fill_parent">        <TabWidget            android:id="@android:id/tabs"            android:layout_width="fill_parent"            android:layout_height="wrap_content" />        <FrameLayout            android:id="@android:id/tabcontent"            android:layout_width="fill_parent"            android:layout_height="fill_parent">            <TextView                 android:id="@+id/textview1"                android:layout_width="fill_parent"                android:layout_height="fill_parent"                 android:text="this is a tab" />            <TextView                 android:id="@+id/textview2"                android:layout_width="fill_parent"                android:layout_height="fill_parent"                 android:text="this is another tab" />            <TextView                 android:id="@+id/textview3"                android:layout_width="fill_parent"                android:layout_height="fill_parent"                 android:text="this is a third tab" />    </FrameLayout>    </LinearLayout></TabHost>

當調用到那個view是將它顯示出來即可。

 

二、Android 9 patch 工具的使用。

        所謂 9-patch drawables,就是將一個 drawable 按照定義的 4 個邊緣的寬度大小切割成9個地區,包括4個角落,4條邊緣和一個中心地區,當把這個 drawable 繪製到一個任意矩形地區時,drawable 的各個地區有不同的展開控制(角落不展開,橫邊橫向展開,豎邊豎向展開,中心地區橫豎向都展開)。通常使用 9-patch drawable 一般是為了繪製出比較漂亮的帶圓角背景,這樣可以避免圓角及邊緣被任意展開導致變形。

 

說明:①左邊和頂部兩條黑線選擇展開的地區

            ②右邊和底部選定content,既文本地區

:

   

 

 參考:http://www.cnblogs.com/qianxudetianxia/archive/2011/04/17/2017591.html

           

http://blog.csdn.net/xiaominghimi/article/details/6107837

聯繫我們

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