Мой ответ будет интересен пользователям Xamarin и MvvmCross.Основная концепция та же, что и в предыдущих сообщениях, поэтому основные шаги:
- Отключение событий прокрутки
- Динамическое изменение высоты списка
Здесь вы помогаетекласс, позволяющий отключить прокрутку в виде списка:
using System;
using Cirrious.MvvmCross.Binding.Droid.Views;
using Android.Content;
using Android.Util;
using Android.Views;
using Android.Database;
namespace MyProject.Android.Helpers
{
public class UnscrollableMvxListView
: MvxListView
{
private MyObserver _myObserver;
public UnscrollableMvxListView (Context context, IAttributeSet attrs, MvxAdapter adapter)
: base(context, attrs, adapter)
{
}
protected override void OnAttachedToWindow ()
{
base.OnAttachedToWindow ();
var dtso = new MyObserver(this);
_myObserver = dtso;
Adapter.RegisterDataSetObserver (dtso);
}
protected override void OnDetachedFromWindow ()
{
Log.Debug ("UnscrollableMvxListView", "OnDetachedFromWindow");
if (_myObserver != null) {
Adapter.UnregisterDataSetObserver (_myObserver);
_myObserver = null;
}
base.OnDetachedFromWindow ();
}
//Make List Unscrollable
private int _position;
public override bool DispatchTouchEvent (MotionEvent ev)
{
MotionEventActions actionMasked = ev.ActionMasked & MotionEventActions.Mask;
if (actionMasked == MotionEventActions.Down) {
// Record the position the list the touch landed on
_position = PointToPosition((int) ev.GetX (), (int) ev.GetY());
return base.DispatchTouchEvent(ev);
}
if (actionMasked == MotionEventActions.Move) {
// Ignore move events
return true;
}
if (actionMasked == MotionEventActions.Up) {
// Check if we are still within the same view
if (PointToPosition((int) ev.GetX(), (int) ev.GetY()) == _position) {
base.DispatchTouchEvent(ev);
} else {
// Clear pressed state, cancel the action
Pressed = false;
Invalidate();
return true;
}
}
return base.DispatchTouchEvent(ev);
}
//Make List Flat
public void JustifyListViewHeightBasedOnChildren () {
if (Adapter == null) {
return;
}
var vg = this as ViewGroup;
int totalHeight = 0;
for (int i = 0; i < Adapter.Count; i++) {
View listItem = Adapter.GetView(i, null, vg);
listItem.Measure(0, 0);
totalHeight += listItem.MeasuredHeight;
}
ViewGroup.LayoutParams par = LayoutParameters;
par.Height = totalHeight + (DividerHeight * (Adapter.Count - 1));
LayoutParameters = par;
RequestLayout();
}
}
internal class MyObserver
: DataSetObserver
{
private readonly UnscrollableMvxListView _unscrollableMvxListView;
public MyObserver (UnscrollableMvxListView lst)
{
_unscrollableMvxListView = lst;
}
public override void OnChanged() {
Log.Debug("UnscrollableMvxListView", "OnChanged");
base.OnChanged ();
_unscrollableMvxListView.JustifyListViewHeightBasedOnChildren ();
}
}
}