開源中國Android版學習筆記(二) layout檔案夾的xml檔案(A)

來源:互聯網
上載者:User

解決了xml檔案夾,向上翻,依次有values,raw,menu,layout等檔案夾,這裡粗略介紹前三個,主要來講lauyout。

首先,values檔案夾的幾個檔案起到的是定義的作用,詳見android項目中values中幾個檔案的作用。raw檔案夾存放的是開源中國的音效檔,menu檔案夾儲存的是菜單,但不知道為什麼這裡只定義了4個按鈕(實際上有六個,而且這裡的四個與顯示出來的六個還不全一致)。若想知道res檔案的所有檔案請單擊這裡。

ok,進入關鍵區段--layout檔案夾。這裡面可有不少xml檔案,但是仔細一看,又有不少共同點,對,很多檔案的首碼名都相似,下面來根據首碼名一一介紹。

1.about.xml:顧名思義,這個檔案寫的是系統設定裡的關於選項,這裡使用了<FrameLayout>標籤,主要作用當然是設定背啦,android:background="@drawable/about_bg",這裡要提一下drawable檔案夾,這裡面是定義了那些圖片檔案,比如about_bg.xml,就是給about.png定義。接下來是三個文字框和一個按鈕,因為FrameLayout布局,所以一一覆蓋在背景圖上,這裡面要注意的是 
android:layout_gravity="center|bottom",它是讓這幾個顯示在置中。

2.active_lisitem,xml:這裡的LinearLayout標籤段中有這麼一段值得注意  android:descendantFocusability="blocksDescendants"
,這裡使用它的原因是:可能會發生點擊每一個item的時候沒有反應,無法擷取的焦點,用了它後view會覆蓋子類控制項而直接獲得焦點。這個檔案的作用是對別人的文章進行評論或者轉寄。這裡布局需要注意一下,下面進行詳細討論:

<?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="wrap_content"    android:descendantFocusability="blocksDescendants"     android:paddingLeft="6dip"    android:paddingRight="6dip"    android:paddingTop="8dip"    android:paddingBottom="7dip">       <ImageView         android:id="@+id/active_listitem_userface"          style="@style/user_face_image"/><LinearLayout    android:layout_width="fill_parent"     android:layout_height="wrap_content"    android:orientation="vertical"    android:layout_marginLeft="6dip">              <TextView        android:id="@+id/active_listitem_username"      android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:includeFontPadding="false"           android:textSize="@dimen/text_size_12"            android:textColor="@color/listitem_gray"/>        <TextView android:id="@+id/active_listitem_content" android:layout_width="wrap_content" android:layout_height="wrap_content"android:layout_marginTop="8dip"android:textSize="@dimen/text_size_15"android:textColor="@color/listitem_black"android:textColorLink="@color/listitem_blue"/>    <ImageView     android:id="@+id/active_listitem_image"      android:layout_width="wrap_content"         android:layout_height="wrap_content"        android:layout_marginTop="8dip"        android:scaleType="fitCenter"        android:src="@drawable/image_loading"        android:visibility="gone"/><TextView android:id="@+id/active_listitem_reply" android:layout_width="fill_parent" android:layout_height="wrap_content"android:layout_marginTop="8dip"android:textSize="@dimen/text_size_15"android:textColor="@color/listitem_black"android:background="@drawable/review_bg_top"/><LinearLayout     android:orientation="horizontal"         android:layout_width="wrap_content"          android:layout_height="wrap_content"        android:layout_marginTop="8dip">           <TextView         android:id="@+id/active_listitem_client"             android:layout_width="wrap_content"          android:layout_height="wrap_content"         android:layout_marginRight="10dip"         android:textSize="@dimen/text_size_10"         android:textColor="@color/listitem_gray"/>            <TextView         android:id="@+id/active_listitem_date"             android:layout_width="wrap_content"          android:layout_height="wrap_content"         android:textSize="@dimen/text_size_10"         android:textColor="@color/listitem_gray"/>             <ImageView       android:layout_width="wrap_content"         android:layout_height="wrap_content"        android:layout_marginLeft="10dip"        android:layout_gravity="center_vertical"        android:src="@drawable/widget_comment_count_icon"/>               <TextView android:id="@+id/active_listitem_commentCount"      android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginLeft="3dip"           android:textSize="@dimen/text_size_10"            android:textColor="@color/listitem_gray"/>                    <ImageView         android:id="@+id/active_listitem_redirect"        android:layout_width="wrap_content"         android:layout_height="wrap_content"        android:layout_marginLeft="10dip"        android:layout_gravity="center_vertical"        android:src="@drawable/widget_redirect_icon"/>        </LinearLayout></LinearLayout></LinearLayout> 


這裡再插入一張圖來給對照。


一個線性布局後首先是一個帳戶圖片圖片,接著繼續一個線性布局,兩個TextView,一個是使用者名稱,一個是目錄(即文章目錄),再接著,一個loading圖(個人估計是回複等待圖,不像是頭像載入),後面是一個回複框,背景圖在android:background="@drawable/review_bg_top"裡,再然後,又是一個線性布局,兩個TextView,一個是用戶端(這個真不好解釋,沒有理解),另一個是顯示時間,後面是兩個圖片,一個顯示評論,一個是轉寄,還有一個TextView,顯示的是評論數量。

這裡面倒也沒有什麼生澀的代碼,只要理解了作用就能看懂了。(我手機用的開源中國和ADT裡的版本是不同的,一個1.0,一個1.7,因為這個,理解代碼是實在是蛋疼不已)。因為檔案數量太多,以後乾脆就以首字母來一篇篇做筆記。

OK,未完待續。

聯繫我們

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