我有一个custom view
,我用它来捕获Android
上的用户签名。 view
工作正常,我得到我想要的结果。现在我需要添加水印(签名框的背景四角上的小文本)。我在Android和iOS上这样做,所以我在iOS上做的是创建label
,并使用一些配置我在运行时计算frame (x,y,width,heigh)
并将它们添加到自定义视图。这适用于iOS(MonoTouch)。现在我需要在MonoForAndroid上做同样的事情。将标签和图像动态添加到Android中的自定义视图中
到目前为止,我得到这个:
// my customView public signatureView : View, ISignatureView { // some irrelvant code here // then OnDraw (which is where I draw the signature line) protected override void OnDraw(Canvas canvas) { DrawWaterMarks(); } private void DrawWaterMarks() { // First, I create a RelativeLayout and add it to my customView to hold the labels _relativeLayout = new RelativeLayout(this.Context); var layoutParam = new RelativeLayout.LayoutParams(this.MeasuredWidth, this.MeasuredHeight); _relativeLayout.LayoutParameters = layoutParam; var viewGroup = (ViewGroup)this.RootView; viewGroup.AddView(_relativeLayout); // I then create the labels ILabel label = new Label(Context); label.Layout(watermark.x, watermark.y, 0,0); EnsureAddingWatermarkControl(label); } private void EnsureAddingWatermarkControl(View view) { if (_relativeLayout != null && view != null) { _relativeLayout.RemoveView(view); _relativeLayout.AddView(view, view.MeasuredWidth, view.MeasuredHeight); this.Invalidate(); } } }
现在上面所有的代码工作正常,没有异常或错误,但我看不到我的任何标签。
我假设它是RelativeLayout以及尺寸的设置和我正在做的方式,但无法解决问题出在哪里。
任何帮助将不胜感激。
是否需要再次添加它?我以为我需要添加一次..我会给这个尝试 –
Ur改变相对布局不反映bcoz,你的rootview不知道它的修改。 – Priya
var viewGroup =(ViewGroup)this.RootView; 你能解释一下你为什么使用这条线吗? – Priya