我想使用代码滚动列表视图。但我不知道卷轴如何在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
};
}
}
}发布于 2017-11-07 06:13:23
为了更容易地实现,请使用RecyclerView和recyclerView.smoothScrollTo(位置)
https://stackoverflow.com/questions/47150652
复制相似问题