添加SignaturePad一个片段/查看 [英] Add SignaturePad to a Fragment / View

查看:1662
本文介绍了添加SignaturePad一个片段/查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我使用VisualStudio的2013年,在xamarin最新版为和MvvmCross。
在过几天我使用Android的Xamarin的lib SignaturePad
https://components.xamarin.com/view/signature-pad

first i use VisualStudio 2013, xamarin in newest ersion and MvvmCross. at a few days i use the lib SignaturePad for Android Xamarin https://components.xamarin.com/view/signature-pad

我有很多标签的每一个标签是一个片段。
在一个片段我想添加签名域或其中的2。但工作不到风度
我想添加的CreateView的方法领域

I have a a lot of Tabs an every Tab is a Fragment. in One Fragment i want to add the Signature Field or 2 of them. but it dosn't work i want to add the Field on the CreateView method

下面的片段的code:

here the Code of the Fragment:

class TakePictureFragment : MvxFragment
{
    private File _dir;
    private File _file;
    private ImageView _imageView;

    public override void OnActivityResult(int requestCode, int resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);

        // make it available in the gallery
        Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
        Uri contentUri = Uri.FromFile(_file);
        mediaScanIntent.SetData(contentUri);
        Activity.SendBroadcast(mediaScanIntent);

        // display in ImageView. We will resize the bitmap to fit the display
        // Loading the full sized image will consume to much memory 
        // and cause the application to crash.
        int height = _imageView.Height;
        int width = Resources.DisplayMetrics.WidthPixels;
        using (Bitmap bitmap = _file.Path.LoadAndResizeBitmap(width, height))
        {
            _imageView.RecycleBitmap();
            _imageView.SetImageBitmap(bitmap);
        }
    }

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        var view = inflater.Inflate(Resource.Layout.TakePicture, null);
        var Layout = new LinearLayout(Activity)
        {
            Orientation = Orientation.Vertical,
            LayoutParameters = new LinearLayout.LayoutParams(container.Width, ViewGroup.LayoutParams.WrapContent)

        };
            //this.BindingInflate(Resource.Layout.TakePicture, null); 

        var signature = new SignaturePadView(Activity);
        signature.Visibility = ViewStates.Visible;
        signature.SetGravity(GravityFlags.Top);
        Layout.AddView(signature, 200, 200);
        container.AddView(Layout);
        /*AddContentView(signature,
            container.LayoutParams(200, 200));*/

        if (IsThereAnAppToTakePictures())
        {
            CreateDirectoryForPictures();

            Button button = view.FindViewById<Button>(Resource.Id.myButton);
            _imageView = view.FindViewById<ImageView>(Resource.Id.imageView1);

            button.Click += TakeAPicture;

        }

        return view;
    }



    private void CreateDirectoryForPictures()
    {
        _dir = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "CameraAppDemo");
        if (!_dir.Exists())
        {
            _dir.Mkdirs();
        }
    }

    private bool IsThereAnAppToTakePictures()
    {
        Intent intent = new Intent(MediaStore.ActionImageCapture);

        IList<ResolveInfo> availableActivities = Activity.PackageManager.QueryIntentActivities(intent, PackageInfoFlags.MatchDefaultOnly);
        return availableActivities != null && availableActivities.Count > 0;
    }

    private void TakeAPicture(object sender, EventArgs eventArgs)
    {
        Intent intent = new Intent(MediaStore.ActionImageCapture);

        _file = new File(_dir, String.Format("myPhoto_{0}.jpg", Guid.NewGuid()));

        intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(_file));

        StartActivityForResult(intent, 0);
    }
}

}

我希望有人能帮助我

Greez

推荐答案

你试过返回容器而不是看法?如果不行,我会放一个Resource.Layout.TakePicture的ViewGroup空,并添加它。

Have you tried returning the container instead of the view? If that doesn't work i would put a empty viewgroup in Resource.Layout.TakePicture, and add it there.

View insertPoint = findViewById(R.id.insert_point);
((ViewGroup) insertPoint).addView(v, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

更新:

在XML中增加一个ViewGroup中,做如下:

To add a viewgroup in xml, do as followed:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/myButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/openCamera" />
    <ImageView
        android:src="@android:drawable/ic_menu_gallery"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:id="@+id/imageView1"
        android:adjustViewBounds="true" />
    <LinearLayout
        android:orientation="vertical"
        android:id="@+id/insert_point"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

然后你可以用 view.findViewById(R.id.insert_point)得到它;!您的信息添加到它

您code应该是这样的:

Your code should look like this:

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    var view = inflater.Inflate(Resource.Layout.TakePicture, null);
    var Layout = new LinearLayout(Activity)
    {
        Orientation = Orientation.Vertical,
        LayoutParameters = new LinearLayout.LayoutParams(container.Width, ViewGroup.LayoutParams.WrapContent)

    };
        //this.BindingInflate(Resource.Layout.TakePicture, null); 

    var signature = new SignaturePadView(Activity);
    signature.Visibility = ViewStates.Visible;
    signature.SetGravity(GravityFlags.Top);
    var insertPoint = view.findViewById(R.id.insert_point);
    insertPoint.AddView(signature);


    if (IsThereAnAppToTakePictures())
    {
        CreateDirectoryForPictures();

        Button button = view.FindViewById<Button>(Resource.Id.myButton);
        _imageView = view.FindViewById<ImageView>(Resource.Id.imageView1);

        button.Click += TakeAPicture;

    }

    return view;
}

这篇关于添加SignaturePad一个片段/查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆