Android 常用代码---UI

1与像素密度无关的触控笔势
权限
代码private static final float DISTANCE_DIP = 16.0f;
private static final float PATH_DIP = 40.0f;
// convert dip measurements to pixels
final float scale = getResources().getDisplayMetrics().density;
int scaledDistance = (int) (DISTANCE_DIP * scale + 0.5f);
int scaledPath = (int) (PATH_DIP * scale + 0.5f);
// For more information about touch gestures and screens support, see:
// http://developer.android.com/resources/articles/gestures.html
// http://developer.android.com/reference/android/gesture/package-summary.html
// http://developer.android.com/guide/practices/screens_support.html
2缩放位图以查看大小
权限
代码originalImage = Bitmap.createScaledBitmap( 
originalImage,     // bitmap to resize
view.getWidth(),   // new width
view.getHeight(),  // new height
true);             // bilinear filtering
3调整 Widget 大小
权限
代码 public void onSizeChanged(int w, int h, int oldW,
int oldH) {
// Calculate relative sizes at runtime
// mButton and mButtonBackGround are of type Drawable
int selfW = mButton.getIntrinsicWidth();
int selfH = mButton.getIntrinsicHeight();
int marginX = (w - selfW) / 2;
int marginY = (h - selfH) / 2;
mButtonBackground.setBounds(marginX, marginY,
marginX + selfW, marginY + selfH);
mButton.setBounds(marginX, marginY,
marginX + selfW, marginY + selfH);
// Implement the measureText method to resize text data, if applicable
measureText();
}
4响应 Widget 交互
权限
代码// Add import android.view.View.OnClickListener; statement
// Add import android.widget.Button; statement
// Add import android.view.View; statement
Button b1 = (Button) findViewById(R.id.your_button_id); // Use this method carefully, it consumes lots of system resources
b1.setOnClickListener(new OnClickListener() {
 public void onClick(View v) {
  // Handle the button click here as you wish
 }
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值