編輯:關於Android編程
package cc.c; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.List; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityManager.MemoryInfo; import android.app.ActivityManager.RunningAppProcessInfo; import android.content.Context; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; /** * Demo描述: * 清理手機內存 * * 參考資料: * 1 http://blog.30c.org/1816.html * 2 http://www.cnblogs.com/helloandroid/archive/2011/10/14/2212334.html * Thank you very much * * 注意權限: ** */ public class MainActivity extends Activity { private TextView mTotalMemoryTextView; private TextView mAvailMemoryTextView; private Button mCleanButton; private TextView mCleanInfoTextView; private ActivityManager mActivityManager; private StringBuffer mCleanInfoStringBuffer; private long availMemory; private long totalMemory; private List mRunningAppProcessInfoList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); } private void init() { mCleanInfoStringBuffer = new StringBuffer(); mActivityManager=(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); mTotalMemoryTextView = (TextView) findViewById(R.id.totalMemoryTextView); mAvailMemoryTextView = (TextView) findViewById(R.id.availMemoryTextView); mCleanInfoTextView = (TextView) findViewById(R.id.cleanInfoTextView); mCleanButton = (Button) findViewById(R.id.cleanButton); totalMemory = getTotalMemory(); availMemory = getAvailMemory(); mTotalMemoryTextView.setText(totalMemory + "MB"); mAvailMemoryTextView.setText(availMemory + "MB"); mCleanButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { RunningAppProcessInfo runningAppProcessInfo=null; mRunningAppProcessInfoList= mActivityManager.getRunningAppProcesses(); //List serviceInfos = mActivityManager.getRunningServices(100); if (mRunningAppProcessInfoList != null) { for (int i = 0; i < mRunningAppProcessInfoList.size(); ++i) { runningAppProcessInfo= mRunningAppProcessInfoList.get(i); // 一般數值大於RunningAppProcessInfo.IMPORTANCE_SERVICE // 的進程即為長時間未使用進程或者空進程 // 一般數值大於RunningAppProcessInfo.IMPORTANCE_VISIBLE // 的進程都是非可見進程,即在後台運行 if (runningAppProcessInfo.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) { String[] pkgList = runningAppProcessInfo.pkgList; for (int j = 0; j < pkgList.length; ++j) { mActivityManager.killBackgroundProcesses(pkgList[j]); mCleanInfoStringBuffer.append(pkgList[j] + " is killed...\n"); mCleanInfoTextView.setText(mCleanInfoStringBuffer.toString()); } } } } //再次獲得剩余內存以計算清理值 mCleanInfoStringBuffer.append("共清理:"+(getAvailMemory() - availMemory) + "MB"); mCleanInfoTextView.setText(mCleanInfoStringBuffer.toString()); mAvailMemoryTextView.setText(getAvailMemory() + "MB"); } }); } private long getTotalMemory() { //系統的內存信息文件 String filePath = "/proc/meminfo"; String lineString; String[] stringArray; long totalMemory = 0; try { FileReader fileReader = new FileReader(filePath); BufferedReader bufferedReader = new BufferedReader(fileReader,1024 * 8); //讀取meminfo第一行,獲取系統總內存大小 lineString = bufferedReader.readLine(); //按照空格拆分 stringArray = lineString.split("\\s+"); //獲得系統總內存,單位KB totalMemory = Integer.valueOf(stringArray[1]).intValue(); bufferedReader.close(); System.out.println("------> lineString=" + lineString+ ",stringArray[0]=" + stringArray[0] + ",stringArray[1]="+ stringArray[1] + ",stringArray[2]=" + stringArray[2]); } catch (IOException e) { } return totalMemory / 1024; } private long getAvailMemory() { MemoryInfo memoryInfo = new MemoryInfo(); mActivityManager.getMemoryInfo(memoryInfo); return memoryInfo.availMem / (1024 * 1024); } }
經常玩兒App的小伙伴都知道,APP上面有很多按鈕都是圓角的,圓形給人感覺飽滿,富有張力,不知道設計圓角按鈕的小伙伴是不是和小編有著相同的想法`(*∩_∩
首先我將貼出幾種實現圓角邊框的dmeo程序效果圖:方式一:使用shape元素填充背景,設置圓角/帶弧度的角1、首先在 \res\drawable下新建Shape為根元素的
一、自定義控件(一) --- 自定義屬性TextView1,定義屬性,制作attrs.xml文件;屬性值:string,color,attr,array,bool,dec
基本框架類定義了一些公用方法來修改該控件的外觀,其中方法如下:setInitView(View view, LayoutParams layoutParams):設置初始