`
xiaoliang330
  • 浏览: 112595 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

android之layout配置文件解读

 
阅读更多
这样的解读在
http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html

标记上,以备忘记

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

  <ListView android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
  <TextView android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_notes"/>

</LinearLayout>





    The @ symbol in the id strings of the ListView and TextView tags means that the XML parser should parse and expand the rest of the id string and use an ID resource.
    The ListView and TextView can be thought as two alternative views, only one of which will be displayed at once. ListView will be used when there are notes to be shown, while the TextView (which has a default value of "No Notes Yet!" defined as a string resource in res/values/strings.xml) will be displayed if there aren't any notes to display.
    The list and empty IDs are provided for us by the Android platform, so, we must prefix the id with android: (e.g., @android:id/list).
    The View with the empty id is used automatically when the ListAdapter has no data for the ListView. The ListAdapter knows to look for this name by default. Alternatively, you could change the default empty view by using setEmptyView(View) on the ListView.

    More broadly, the android.R class is a set of predefined resources provided for you by the platform, while your project's R class is the set of resources your project has defined. Resources found in the android.R resource class can be used in the XML files by using the android: name space prefix (as we see here).




<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/text1"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>




This is the View that will be used for each notes title row — it has only one text field in it.

In this case we create a new id called text1. The + after the @ in the id string indicates that the id should be automatically created as a resource if it does not already exist, so we are defining text1 on the fly and then using it.





<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	
	<LinearLayout android:orientation="horizontal"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content">

		<TextView android:layout_width="wrap_content"
			android:layout_height="wrap_content" 
			android:text="@string/title" />
		<EditText android:id="@+id/title" 
		  android:layout_width="wrap_content"
			android:layout_height="wrap_content" 
			android:layout_weight="1"/>
	</LinearLayout>

	<TextView android:layout_width="wrap_content"
		android:layout_height="wrap_content" 
		android:text="@string/body" />
	<EditText android:id="@+id/body" android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:layout_weight="1"
		android:scrollbars="vertical" />
	
	<Button android:id="@+id/confirm" 
	  android:text="@string/confirm"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content" />

</LinearLayout>





layout_weight is used in LinearLayouts to assign "importance" to Views within the layout. All Views have a default layout_weight of zero, meaning they take up only as much room on the screen as they need to be displayed. Assigning a value higher than zero will split up the rest of the available space in the parent View, according to the value of each View's layout_weight and its ratio to the overall layout_weight specified in the current layout for this and other View elements.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics