现在的位置: 首页 > 综合 > 正文

开源中国Android版学习笔记(二) layout文件夹的xml文件(A)

2012年10月22日 ⁄ 综合 ⁄ 共 4095字 ⁄ 字号 评论关闭

解决了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,未完待续。

抱歉!评论已关闭.