我有 4行,我想与小部件高度动态匹配。 每行将获得小部件总高度的25%。
我没有运气尝试过的事情:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.gridholder);
Intent intent = new Intent(context.getApplicationContext(), Gridfactory.class);
resizedGrid item = (resizedGrid) ((Activity) context).findViewById(R.layout.grid_view);
views.setRemoteAdapter(item.getId(), intent);
private class resizedGrid extends GridView {
public resizedGrid(Context context) {
super(context);
}
public resizedGrid(Context context, AttributeSet attrs) {
super(context, attrs);
}
public resizedGrid(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightSpec;
if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
} else {
heightSpec = heightMeasureSpec;
}
super.onMeasure(widthMeasureSpec, heightSpec);
}
}