37、进程管理器--界面设计

创建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;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

asmcvc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值