列表视图的老虎机

时间:2017-11-07 05:35:26

标签: c# android listview xamarin scroll

我想使用代码滚动列表视图。但我不知道ListView中的滚动工作如何,如何获得位置。我使用ScrollTo来改变位置,但是位置没有改变

计划:滚动使用方法ScrollTo的每个刻度移动位置。如果是边界,则在反对边界设置位置。

using Android.App;
using Android.Widget;
using Android.OS;
using System;
using Android.Media;
using System.Collections.Generic;
using Android.Views;

namespace TestChart
{
    [Activity(Label = "Slot Machine", MainLauncher = true)]
    public class MainActivity : Activity
    {
        String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
                "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
                "Linux", "OS/2","Android", "iPhone", "WindowsMobile",
                "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
                "Linux", "OS/2" };


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

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            Button buttonRoll = FindViewById<Button>(Resource.Id.buttonRoll);
            ListView listViewSlotMachine = FindViewById<ListView>(Resource.Id.listViewSlotMachine);

            var adapter = new ArrayAdapter<String>(this, Resource.Layout.my_list_item, values);

            listViewSlotMachine.Adapter = adapter;

            buttonRoll.Click += (sender, e) =>
            {
                listViewSlotMachine.ScrollTo(0, 0); // don't changed
            };
        }
    }
}

1 个答案:

答案 0 :(得分:0)

为了便于实施,请使用RecyclerView与recyclerView.smoothScrollTo(位置)