对于程序员来说,最头痛的就是UI界面的设计,而在android中,只能自已做界面。有时就在想,别人是怎么写出那样好看的界面的。
Android给我们提供了一个很好的工具,可以查看正在运行的界面的设计:hierarchyviewer.bat
使用方法:
第一:运行一个模拟器,并打开要查看的UI界面。
第二:运行android-sdk-windows\tools包下的hierarchyviewer.bat工具
第三:选择你要进行查看的模拟器(如果你打开了多个)
第四:点击菜单中的Hierarchy-->Load View Hierarchy,就可以查看了。
虽然不是很具体,但是可以得到基本的思路和层次结构的实现,这对于程序员来说,已经是很大的帮助了。
public boolean contactExists(Context context, String number) {
/// number is the phone number
Uri lookupUri = Uri.withAppendedPath(
PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(number));
String[] mPhoneNumberProjection = { PhoneLookup._ID, PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };
Cursor cur = context.getContentResolver().query(lookupUri,mPhoneNumberProjection, null, null, null);
try {
if (cur.moveToFirst()) {
return true;
}
} finally {
if (cur != null)
cur.close();
}
return false;
}
private static final int PROGRESS = 0x1;
private static final int MAX_PROGRESS = 100;
private int mProgressStatus = 10;
private Handler mHandler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.twolayout);
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.icon; //通知图标
CharSequence tickerText = "Hello"; //状态栏显示的通知文本提示
long when = System.currentTimeMillis(); //通知产生的时间,会在通知信息里显示
//用上面的属性初始化Nofification
Notification notification = new Notification(icon,tickerText,when);
final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
contentView.setProgressBar(R.id.progress_bar, MAX_PROGRESS, mProgressStatus, false);
notification.contentView = contentView;
// Start file upload in a background thread
new Thread(new Runnable() {
public void run() {
while (mProgressStatus < MAX_PROGRESS) {
mProgressStatus += mProgressStatus;
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
contentView.setProgressBar(R.id.progress_bar, MAX_PROGRESS, mProgressStatus, false);
}
});
}
}
}).start();
Intent notificationIntent = new Intent(this,TestTwoDScrollView.class);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
notification.contentIntent = contentIntent;
manager.notify(1, notification);