android 常用UI使用工具代码片段
2011-06-19 18:24
531 查看
/*
* 常用UI使用工具
*/
//***与像素密度无关的触控笔势
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
//***缩放位图以查看大小
originalImage = Bitmap.createScaledBitmap(
originalImage, // bitmap to resize
view.getWidth(), // new width
view.getHeight(), // new height
true); // bilinear filtering
//***调整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();
}
//***响应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
}
});
* 常用UI使用工具
*/
//***与像素密度无关的触控笔势
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
//***缩放位图以查看大小
originalImage = Bitmap.createScaledBitmap(
originalImage, // bitmap to resize
view.getWidth(), // new width
view.getHeight(), // new height
true); // bilinear filtering
//***调整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();
}
//***响应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
}
});
相关文章推荐
- Android 开发常用代码片段
- Android:常用代码片段整理
- Android上架相关(代码混淆和反编译工具的使用,签名,打包,加固)
- Android 开发常用代码片段
- Android 开发常用代码片段
- android常用的代码片段
- Android 开发常用代码片段
- Android常用代码片段
- Android布局常用代码片段
- Android代码优化——使用Android lint工具(才发现这是个不错的工具)
- 36个Android开发常用代码片段
- # AndroidStudio 常用工具和使用技巧(持续更新)
- Android常用控件八之使用RadioButton切换图片,代码实例
- android常用UI使用案例:ImageSwitcher和Gallery
- Android 开发常用代码片段
- Android常用代码片段
- Android 开发常用代码片段
- android开发过程中使用功能性代码片段(一)
- Android开发UI之常用控件的使用
- Android获取各个应用程序的缓存文件代码小片段(使用AIDL)