如何在对话框片段中实现幻灯片到下一张图片?

时间:2017-01-27 10:45:53

标签: xamarin.android android-dialogfragment

我一直在google上搜索一些有用的例子,但是我找不到一些......当我点击我的详细活动中的片段时,我试图实现向左/向右滑动,我有5个ImageView和当你点击图像视图时,它将全屏展开..,我想要发生的是当你向左或向右滑动我想要转到下一个图像..我怎么能这样做?提前谢谢你:)

到目前为止:

MyDialogFragment类。

public class MyDialogFragment : DialogFragment
{
    ImageView imgf;

    public static MyDialogFragment newInstance()
    {
        MyDialogFragment f = new MyDialogFragment();
        return f;
    }

    public override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        SetStyle(DialogFragmentStyle.NoTitle, Android.Resource.Style.ThemeBlackNoTitleBarFullScreen);
    }

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View v = inflater.Inflate(Resource.Layout.fragment_dialog, container, false);

        imgf = v.FindViewById<ImageView>(Resource.Id.imageFragment);

        int image = this.Arguments.GetInt("IMG1");

        imgf.SetImageResource(image);

        return v;
    }
}

我的DetailActivity;

public class DetailActivity:Activity     {

    private ImageView mtimg0, mtimg1, mtimg2, mtimg3, mtimg4, mtimg5;        

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.detailLayout);

        FindViews();            

        Android.Content.Intent i = this.Intent;
        string iname = i.Extras.GetString("MTNAME");
        int iimg0 = i.Extras.GetInt("IMG0");
        int iimg1 = i.Extras.GetInt("IMG1");
        int iimg2 = i.Extras.GetInt("IMG2");
        int iimg3 = i.Extras.GetInt("IMG3");
        int iimg4 = i.Extras.GetInt("IMG4");
        int iimg5 = i.Extras.GetInt("IMG5");

        tmtname.Text = iname;
        mtimg0.SetImageResource(iimg0);
        mtimg1.SetImageResource(iimg1);
        mtimg2.SetImageResource(iimg2);
        mtimg3.SetImageResource(iimg3);
        mtimg4.SetImageResource(iimg4);
        mtimg5.SetImageResource(iimg5);    


        mtimg0.Click += Mtimg0_Click;
        mtimg1.Click += Mtimg1_Click;
        mtimg2.Click += Mtimg2_Click;
        mtimg3.Click += Mtimg3_Click;
        mtimg4.Click += Mtimg4_Click;
        mtimg5.Click += Mtimg5_Click;
    }

    private void Mtimg0_Click(object sender, System.EventArgs e)
    {
        Intent i = this.Intent;
        int iimg0 = i.Extras.GetInt("IMG0");
        OpenFragment(iimg0);
    }
    private void Mtimg1_Click(object sender, System.EventArgs e)
    {
        Intent i = this.Intent;
        int iimg1 = i.Extras.GetInt("IMG1");
        OpenFragment(iimg1);

    }
    private void Mtimg2_Click(object sender, System.EventArgs e)
    {
        Intent i = this.Intent;
        int iimg2 = i.Extras.GetInt("IMG2");
        OpenFragment(iimg2);

    }
    private void Mtimg3_Click(object sender, System.EventArgs e)
    {
        Intent i = this.Intent;
        int iimg3 = i.Extras.GetInt("IMG3");
        OpenFragment(iimg3);

    }
    private void Mtimg4_Click(object sender, System.EventArgs e)
    {
        Intent i = this.Intent;
        int iimg4 = i.Extras.GetInt("IMG4");
        OpenFragment(iimg4);

    }
    private void Mtimg5_Click(object sender, System.EventArgs e)
    {
        Intent i = this.Intent;
        int iimg5 = i.Extras.GetInt("IMG5");
        OpenFragment(iimg5);
    }

    private void FindViews()
    {
        mtimg0 = FindViewById<ImageView>(Resource.Id.mtimg00); 
        mtimg1 = FindViewById<ImageView>(Resource.Id.mtimg01);
        mtimg2 = FindViewById<ImageView>(Resource.Id.mtimg02);
        mtimg3 = FindViewById<ImageView>(Resource.Id.mtimg03);
        mtimg4 = FindViewById<ImageView>(Resource.Id.mtimg04);
        mtimg5 = FindViewById<ImageView>(Resource.Id.mtimg05);           
    }

    private void OpenFragment(int img1)
    {
        Bundle b = new Bundle();
        b.PutInt("IMG1", img1);

        MyDialogFragment fragment = new MyDialogFragment();
        fragment.Arguments = b;

        fragment.Show(this.FragmentManager, "dialog");
    }
}

0 个答案:

没有答案