【发布时间】:2014-03-25 07:00:43
【问题描述】:
我正在开发生日祝福应用程序。我想在手机的主屏幕上设置我朋友生日的提醒。但我想要像自定义小部件一样查看它。谁能帮我了解如何在android中动态创建小部件?那就是使用编码。
【问题讨论】:
标签: android android-layout android-widget
我正在开发生日祝福应用程序。我想在手机的主屏幕上设置我朋友生日的提醒。但我想要像自定义小部件一样查看它。谁能帮我了解如何在android中动态创建小部件?那就是使用编码。
【问题讨论】:
标签: android android-layout android-widget
public class DynamicImageButton extends ImageView {
public DynamicImageButton(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
final Drawable d = this.getDrawable();
if (d != null) {
// ceil not round - avoid thin vertical gaps along the left/right edges
final int width = MeasureSpec.getSize(widthMeasureSpec);
final int height = (int) Math.ceil(width * (float) d.getIntrinsicHeight() / d.getIntrinsicWidth()-10);
this.setMeasuredDimension(width, height);
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
【讨论】: