android:width="3dp"
android:color="@color/gray4"/>
android:drawable="@drawable/dot_pattern_bitmap"/>
这是在自定义的FrameLayout customView.xml使用:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/layers"/>
它本身被用于例如在
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/space_m"
android:orientation="vertical">
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
此外,我有CustomView.java类来编辑自定义视图(特别是图层)的行为。
在那里,我试图根据customView的大小(和参数'ratio')实现层列表大小的更新。我试过这样:
// ...
@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
layoutWidth = MeasureSpec.getSize(widthMeasureSpec);
layoutHeight = MeasureSpec.getSize(heightMeasureSpec);
readjustSize(ratio);
}
private void readjustSize(final double ratio) {
if (layoutHeight != 0 && layoutWidth != 0) {
// determine desired width and height using the layout width
int desiredWidth = layoutWidth;
int desiredHeight = (int) (layoutWidth/ratio);
// if it does not fit, adjust using the layout height
if (desiredHeight > layoutHeight) {
desiredHeight = layoutHeight;
desiredWidth = (int) (layoutHeight * ratio);
}
// get the basic layer
final LayerDrawable ld =
(LayerDrawable) ContextCompat.getDrawable(getContext(), R.layers);
final GradientDrawable outerRectShape =
(GradientDrawable) ld.findDrawableByLayerId(R.id.outer_rect);
// and adapt the size
outerRectShape.setSize(desiredWidth, desiredHeight);
outerRectShape.setBounds(0, 0, desiredWidth, desiredHeight);
// redraw
invalidate();
requestLayout();
}
}
所以,那是很多代码...不幸的是,这不能正常工作。如果第一次加载框架布局,我只能看到一个非常小的矩形。
是否有人有想法:
只有当我来回切换这个观点,因为我想规模应用?
2016-10-18
Caro
+0
将ImageView设置为match_parent的宽度。 –
+0
ImageView本身的宽度上有match_parent。包含视图不会,但我已经尝试了宽度和高度的match_parent,仅限宽度或没有(如发布)。这没有任何改变。 –
+0
在FrameLayout中,它是wrap_content。 –