【发布时间】:2016-11-06 17:59:07
【问题描述】:
我的 ImageView 与 x 轴上的屏幕尺寸匹配,并且在我的布局中使用 y 轴上的剩余空间。我想在这个 ImageView 中创建与 ImageView 完全相同大小的位图。请问如何制作?可以通过一些自动设置来完成,我应该调用一些测量函数吗?
我尝试了 SetAdjustViewBounds(),但它对我不起作用。
创建足够大的位图(我不喜欢这样浪费内存)和设置 SetScaleType(ImageView.ScaleType.Matrix) 有效,但是当我在画布上进行绘图操作时,我不知道我应该绘制的区域的实际大小,画布和位图高度都等于 yScreen,而 imgWeekView 高度假装为 0,即使它用灰色绘制整个所需区域。
imgWeekView = new ImageView(context);
//imgWeekView.SetAdjustViewBounds(true);
imgWeekView.SetScaleType(ImageView.ScaleType.Matrix);
layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent,1f);
layoutParams.Height = 0;
imgWeekView.LayoutParameters = layoutParams;
Bitmap bitmap = Bitmap.CreateBitmap((int)xScreen, (int)yScreen, Bitmap.Config.Argb8888);
cnvWeekView = new Canvas(bitmap);
imgWeekView.SetImageBitmap(bitmap);
linearLayout.AddView(imgWeekView); //whole activity layout
//Test
cnvWeekView.DrawColor(new Color(128, 128, 128));
Paint paint = new Paint(PaintFlags.AntiAlias);
paint.Color = new Color(255, 255,0);
cnvWeekView.DrawCircle(50, 50, 40, paint);
【问题讨论】:
标签: layout bitmap imageview xamarin.android measure