让自己的Android应用支持appwidget
2010-12-18 08:04:06 来源:WEB开发网}
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
cellInfo[0] = (int)event.getX();
cellInfo[1] = (int)event.getY();
return super.dispatchTouchEvent(event);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
LayoutParams lp;
for(int index=0; index< index++)>
lp = (LayoutParams) getChildAt(index).getLayoutParams();
getChildAt(index).layout(lp.x, lp.y, lp.x+lp.width, lp.y+lp.height);
}
}
public static class LayoutParams extends ViewGroup.LayoutParams {
int x;
int y;
public LayoutParams(int width, int height) {
super(width, height);
}
}
}
package chroya.demo.widget;
import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
/**
* 承载widget的容器
* @author chroya
*/
public class WidgetLayout extends ViewGroup {
//存放touch的坐标
private int[] cellInfo = new int[2];
private OnLongClickListener mLongClickListener;
public WidgetLayout(Context context) {
super(context);
mLongClickListener = new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return false;
}
};
}
public void addInScreen(View child, int width, int height) {
LayoutParams lp = new LayoutParams(width, height);
lp.x = cellInfo[0];
lp.y = cellInfo[1];
child.setOnLongClickListener(mLongClickListener);
addView(child, lp);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
点击下载:附件下载
更多精彩
赞助商链接