如何创建行数不总是相同的滚动列表?

时间:2019-05-21 14:25:54

标签: c# xna

我的滚动列表并不总是具有相同的行数,并且当最后一行在滚动列表的底部完全可见时,我想禁用向下滚动。

但是现在,如果最后一行(在本例中为第13行)在列表底部完全可见,则仍然可以向下滚动。然后它看起来像第三张图像(在更多滚动之后),但是我希望它看起来像第二张图像(在滚动之后)。

我该怎么办,以使在最后一行完全可见之后您无法继续向下滚动?

更新:现在可以使用。此代码版本使用可变的滚动速度。

scroll list pictures

我的代码:

//Creating the scroll list: 

public List<Vector2> ScrolllistInitialRowPosYList = new List<Vector2>();
public List<Vector2> ScrolllistRowPosYList = new List<Vector2>();
Microsoft.Xna.Framework.Rectangle ScrollPointRectangle, tappRect, ScrollRectangle;
int ScrollLimitTopPosY = 200, ScrollLimitBottomPosY = 400, RowHeight = 60, ScrollPointStartPosY;
float ScrollAreaHeight, HeightallRows, ScrollSpeed;

ScrollPointStartPosY = ScrollLimitTopPosY;
ScrollPointRectangle = new Microsoft.Xna.Framework.Rectangle(500, ScrollPointStartPosY, ScrollPointSprite.Width, ScrollPointprite.Height);
tappRect = new Microsoft.Xna.Framework.Rectangle(-150, -100, 10, 10);
ScrollRectangle = new Microsoft.Xna.Framework.Rectangle(500, 300, ScrollRectangleSprite.Width, ScrollRectangleSprite.Height);

int FirstRowPosY = 0;
int NumberofRows = 13;
ScrollAreaHeight = ScrollLimitBottomPosY - ScrollLimitTopPosY;
int ListViewportHeight = 6 * RowHeight;
HeightallRows = NumberofRows * RowHeight - ListViewportHeight;

ScrollSpeed = HeightallRows / ScrollAreaHeight;

for (int i = 0; i <= NumberofRows - 1; i++)
{
     ScrolllistInitialRowPosYList.Add(new Vector2(500, FirstRowPosY));
     ScrolllistRowPosYList.Add(new Vector2(500, FirstRowPosY));                     
     FirstRowPosY += RowHeight;
}

//Updating gestures:

                    case GestureType.FreeDrag:
                    if (tappRect.Intersects(ScrollRectangle))
                    {
                        tappRect = new Microsoft.Xna.Framework.Rectangle((int)gs.Position.X, (int)gs.Position.Y, 10, 10);

                            if (gs.Delta.Y > 0)
                            {
                             if (ScrollPointRectangle.Y >= ScrollLimitTopPosY + 2)
                                ScrollPointRectangle = new Microsoft.Xna.Framework.Rectangle(500, ScrollPointRectangle.Y - 2, ScrollPointSprite.Width, ScrollPointSprite.Height);
                          else
                                ScrollPointRectangle = new Microsoft.Xna.Framework.Rectangle(500, ScrollLimitTopPosY, ScrollPointSprite.Width, ScrollPointSprite.Height);
                            }
                            else
                            {
                                if (gs.Delta.Y < 0)
                                {
                                    if (ScrollPointRectangle.Y <= ScrollLimitBottomPosY - 2)
                                      ScrollPointRectangle = new Microsoft.Xna.Framework.Rectangle(500, ScrollPointRectangle.Y + 2, ScrollPointSprite.Width, ScrollPointSprite.Height);
                                    else
                                      ScrollPointRectangle = new Microsoft.Xna.Framework.Rectangle(500, ScrollLimitBottomPosY, ScrollPointSprite.Width, ScrollPointSprite.Height);
                                }
                            }
                    }
                    break;

//Updating the scroll list after someone srolled up or down:

        for (int i = 0; i <= ScrolllistRowPosYList.Count - 1; i++)
        {
            int ScrollPosYCurrent = ScrollPointRectangle.Y;

            int ScrollPosYDifference = ScrollPosYCurrent - ScrollPointStartPosY;
            float RowPosYDifference = ScrollSpeed * ScrollPosYDifference;

            int RowInitialPosY = (int)ScrolllistInitialRowPosYList[i].Y;

            float RowCurrentPosY = RowInitialPosY - RowPosYDifference;

            ScrolllistRowPosYList[i] = new Vector2(ScrolllistRowPosYList[i].X, RowCurrentPosY);
        }

1 个答案:

答案 0 :(得分:0)

  1. 您无法绘制它们。
  2. 您可能有2个List<row>变量,其中一个将存储所有行,另一个仅存储应查看并与之交互的行。

编辑:我读错了。忘记我写的第一点。 使用第二点中的两个列表。滚动时,检查最后一个可见行是否是“所有行”列表中的最后一行。如果是这样,请勿滚动。