0
我已創建自定義視圖組。根據父寬度和高度調整子視圖的尺寸
<com...Template
android:id="@+id/template"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight=".5" />
我在運行時動態添加上面的佈局。
Template.java
currentTemplateView = LayoutInflater.from(context).inflate(R.layout.template_one, this, false);
addView(currentTemplateView, 0);
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
Log.e("Onla", "" + l + t);
int row, col, left, top;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
}
// addView(currentTemplateView, 0);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int mode = MeasureSpec.getMode(widthMeasureSpec); // mode == View.MesaureSpec.EXACTLY
int size = MeasureSpec.getSize(widthMeasureSpec); // size == 400
Log.e("onmeasure", "Width: " + mode + "," + size);
for (int i = 0; i < getChildCount(); i++) {
measureChildWithMargins(getChildAt(i), widthMeasureSpec, 0, heightMeasureSpec, 0);
// getChildAt(i).measure(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec));
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
當我在列表或網格視圖中使用。視圖組中的子項已摺疊。它應該適合父視圖組(template.java)。
我想作爲的ViewGroup看起來像一圖像尺寸調整無論我做的。讓我什麼,我需要在我的代碼或這方面的任何想法來改變..提前
感謝。