程序使用到的界面文件定义在res/layout目录下,其中,main.xml文件定义MainActivity的界面,它的内容如下所示:
- <?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"
- android:gravity="bottom">
- <ListView
- android:id="@+id/listview_article"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="@drawable/border"
- android:choiceMode="singleChoice">
- </ListView>
- <LinearLayout
- android:orientation="horizontal"
- android:layout_height="wrap_content"
- android:layout_width="match_parent"
- android:gravity="center"
- android:layout_marginTop="10dp">
- <Button
- android:id="@+id/button_add"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingLeft="15dp"
- android:paddingRight="15dp"
- android:text="@string/add">
- </Button>
- </LinearLayout>
- </LinearLayout>
item.xml文件定义了ListView中每一个文章信息条目的显示界面,它的内容如下所示: - <?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="wrap_content">
- <TextView
- android:id="@+id/textview_article_title"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </TextView>
- <TextView
- android:id="@+id/textview_article_abstract"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </TextView>
- <TextView
- android:id="@+id/textview_article_url"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="10dp">
- </TextView>
- </LinearLayout>
article.xml文件定义了ArticleActivity的界面,它的内容如下所示: - <?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"
- android:gravity="center">
- <LinearLayout
- android:orientation="horizontal"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginRight="24dp"
- android:text="@string/title">
- </TextView>
- <EditText
- android:id="@+id/edit_article_title"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </EditText>
- </LinearLayout>
- <LinearLayout
- android:orientation="horizontal"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/abs">
- </TextView>
- <EditText
- android:id="@+id/edit_article_abstract"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- </EditText>
- </LinearLayout>
- <LinearLayout
- android:orientation="horizontal"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginRight="27dp"
- android:text="@string/url">
- </TextView>
- <EditText
- android:id="@+id/edit_article_url"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- </EditText>
- </LinearLayout>
- <LinearLayout
- android:orientation="horizontal"
- android:layout_height="wrap_content"
- android:layout_width="match_parent"
- android:gravity="center"
- android:layout_marginTop="10dp">
- <Button
- android:id="@+id/button_modify"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/modify">
- </Button>
- <Button
- android:id="@+id/button_delete"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/delete">
- </Button>
- <Button
- android:id="@+id/button_add_article"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingLeft="16dp"
- android:paddingRight="16dp"
- android:text="@string/add">
- </Button>
- <Button
- android:id="@+id/button_cancel"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/cancel">
- </Button>
- </LinearLayout>
- </LinearLayout>
在res/drawable目录下,有一个border.xml文件定义了MainActivity界面上的ListView的背景,它的内容如下所示: -
<?xml version="1.0" encoding="utf-8"?> -
<shape xmlns:android="http://schemas.android.com/apk/res/android" -
android:shape="rectangle"> -
<solid android:color="#ff0000ff"/> -
<stroke android:width="1dp" -
-
-
<padding android:left="7dp" -
-
-
-
-
<corners android:radius="10dp" /> -
程序使用到的字符串资源文件定义在res/values/strings.xml文件中,它的内容如下所示: -
<?xml version="1.0" encoding="utf-8"?> -
-
<string name="app_name">Article</string> -
<string name="article">Article</string> -
<string name="add">Add</string> -
<string name="modify">Modify</string> -
<string name="delete">Delete</string> -
<string name="title">Title:</string> -
<string name="abs">Abstract:</string> -
<string name="url">URL:</string> -
<string name="ok">OK</string> -
<string name="cancel">Cancel</string> -
本文转自 Luoshengyang 51CTO博客,原文链接:http://blog.51cto.com/shyluo/966944,如需转载请自行联系原作者