2014-03-25 1 views
0

생일 소원 앱을 만들고 있습니다. 모바일의 메인 화면에서 친구들의 생일을 알리는 알림을 만들고 싶습니다. 그러나 나는 그것의 전망을 맞춤 위젯과 같이 원한다. 아무도 안드로이드에서 위젯을 동적으로 생성하는 방법에 대해 나를 도울 수 있습니까? 그것은 코딩을 사용하는 것입니다.android에서 맞춤 위젯을 만드는 방법

+0

당신이 방문해야 http://developer.android.com/training/custom-views/index.html – Kedarnath

답변

1
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); 
     } 
    } 
} 

This will be