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。 –