创建android component:TaskManagerActivity,并为其创建布局文件taskmanager_layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView style="@style/title_center_text"
android:text="进程管理器"/>
<View style="@style/splitter_view"/>
<LinearLayout style="@style/horizontal_linearlayout">
<Button
android:id="@+id/bt_task_user"
android:text="用户进程"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:gravity="center"/>
<Button
android:id="@+id/bt_task_system"
android:text="系统进程"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent">
<RelativeLayout
android:layout_alignParentTop="true"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1">
<ListView
android:id="@+id/lv_usertask"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<ListView
android:id="@+id/lv_systemtask"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</RelativeLayout>
<LinearLayout
android:layout_weight="0"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom="true">
<Button
android:onClick="selectAll"
android:text="全选"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:gravity="center"/>
<Button
android:onClick="oneKeyClear"
android:text="一键清理"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
技巧总结:
在垂直布局的LinearLayout中控件从上往下依次排列,除了标题外我们想把底部的空间全部使用起来,因此可以嵌入一个RelativeLayout,高度和宽度均是match_parent,
这样的属性不会遮挡住标题头,而是从已经排列的控件开始排列。
然后在这个RelativeLayout中设置一个垂直布局的LinearLayout,并且全部填充父容器。在里面的包含listview的容器设置layout_weight为1,包含底部button的容器的layout_weight为0,表示包含listview的容器占满剩余空间。
listview的每一个item的布局文件可以参考《33、程序管理器--界面设计》,只是在右侧多了一个checkbox而已:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:id="@+id/ll_taskmanager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv_taskmanager_icon"
android:layout_height="60dip"
android:layout_width="60dip"
android:layout_weight="0"
android:layout_gravity="left"/>
<RelativeLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView style="@style/content_text"
android:id="@+id/tv_taskmanager_name"
android:layout_alignParentTop="true"
android:singleLine="true"
android:ellipsize="end"
android:textSize="20sp"/>
<TextView style="@style/content_text"
android:id="@+id/tv_taskmanager_mem"
android:layout_alignParentBottom="true"
android:textSize="12sp"/>
</RelativeLayout>
<CheckBox
android:layout_weight="0"
android:id="@+id/cb_taskmanager"
android:focusable="false"
android:clickable="false"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout>
点击“一键清理”杀死所选进程,弹出自定义吐司:
吐司代码:
package com.example.mobilesafe.engine;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.example.mobilesafe.R;
/**
* Created by sing on 14-1-26.
* desc:
*/
public class MyToast {
private static final String TAG = "MyToast";
/**
* 显示自定义的土司
* @param text 显示的内容
*/
public static void showToast(Context context, String text) {
Toast toast = new Toast(context);
View view = View.inflate(context, R.layout.mytoast, null);
TextView tv = (TextView) view.findViewById(R.id.tv_toast);
//设置显示内容
tv.setText(text);
toast.setView(view);
//设置Toast显示的时长。0表示短,1表示常
toast.setDuration(1);
//设置Toast显示在窗体中的位置(这里是显示在窗体中央)
toast.setGravity(Gravity.CENTER, 0, 0);
//将Toast显示出来
toast.show();
}
}
吐司的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="@drawable/call_locate_orange"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/notification" />
<TextView
android:id="@+id/tv_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="我是土司" />
</LinearLayout>
最后在MainActivity中添加代码:
case 3: //进程管理
intent = new Intent(MainActivity.this, TaskManagerActivity.class);
startActivity(intent);
break;
本文详细介绍了一款Android进程管理应用的设计过程,包括主要活动组件TaskManagerActivity的布局设计及其实现技巧。文章展示了如何利用LinearLayout和RelativeLayout实现界面元素的合理布局,并提供了listview item的具体布局方案。
307

被折叠的 条评论
为什么被折叠?



