强制 gridview 绘制所有图块

发布于 2024-12-10 00:36:35 字数 4805 浏览 1 评论 0原文

我有一个 android gridview,我正在使用一些自定义滚动,让它在二维中滚动 - 这意味着默认滚动不会被调用。

我怀疑这可能是屏幕外的行不可见的原因。我知道它们在那里,它们影响布局和一切,但它们从不绘制。

所以我的问题是 - 有什么方法可以强制 gridview 在加载时绘制所有图块,而不仅仅是可见的图块?

谢谢。

编辑:为了澄清 - 在我的tileadapter中,我将子计数设置为225。在我的gridview中,对 getChildCount() 的调用返回165。

再次编辑:只有当gridview的高度大于屏幕的高度时才会发生这种情况- y 轴上超出屏幕的子项只需从子项计数中减去 - 将子项的大小设置为一个数字,使其全部紧贴在屏幕上可以消除问题,但会破坏滚动。

代码!

活动的 XML 布局:

  <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:theme="@style/Theme.Custom"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <TextView android:id="@+id/logmessage"
  android:theme="@style/Theme.Custom"
  android:layout_width="fill_parent"
  android:layout_height="25dip"
  android:text="LogMessage"/>

  <RelativeLayout android:id="@+id/boardwrap"
  android:layout_weight="1"
  android:layout_height="fill_parent"
  android:layout_width="fill_parent"
  android:gravity="center_vertical">
  <com.MyProject.GameGrid 
    android:id="@+id/board"
    android:theme="@style/Theme.Custom"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:numColumns="15"
    android:stretchMode="none"
    android:verticalSpacing="0dip"
    android:horizontalSpacing="0dip"
    android:padding="0dip"
    android:columnWidth="20dip"
    android:scrollbars="none"/>
</RelativeLayout>
<RelativeLayout 
    android:id="@+id/toolbar"
    android:layout_width="fill_parent"
    android:layout_height="60dip"
    android:background="#FFFFFFFF"/>
</LinearLayout>

活动:

public class GameBoardActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gameboard);

        GameGrid Board = (GameGrid)findViewById(R.id.board);
        Board.setAdapter(new TileAdapter(this));
    }
}

GameGrid:

public GameGrid(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.setNumColumns(15);

        DisplayMetrics metrics = new DisplayMetrics();
        ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
        scale = metrics.density;
        smallSize = Math.round(20 * scale);
        largeSize = Math.round(40 * scale);

        columnwidth = largeSize;
        this.setColumnWidth(columnwidth);
        Common.DebugMessage(Float.toString(columnwidth));

    }

您可能会注意到我在这里定义了小尺寸和大尺寸 - 双击屏幕可以在两者之间切换。

滚动(您之前帮助我的)

if (myState == TOUCH_STATE_SCROLLING) {
                    final int deltaX = (int) (mLastX - x);
                    final int deltaY = (int) (mLastY - y);
                    mLastX = x;
                    mLastY = y;

                    int xpos = this.getScrollX();
                    int ypos = this.getScrollY();

                    int maxX = (columnwidth * 15) - super.getWidth();
                    int maxY = (columnwidth * 15) - super.getHeight();

                    if (xpos + deltaX >= 0 && xpos + deltaX <= maxX && ypos + deltaY >= 0 && ypos + deltaY <= maxY )
                    {
                        this.scrollBy(deltaX, deltaY);
                    }
                    else {
                        this.scrollTo(xpos + deltaX <= 0 ? 0 : xpos + deltaX >= maxX ? maxX : xpos + deltaX,
                                      ypos + deltaY <= 0 ? 0 : ypos + deltaY >= maxY ? maxY : ypos + deltaY);
                    }
                    Common.DebugMessage(this.getChildCount());

                }

Common.DebugMessage 只是将调试消息打印到 LogCat

TileAdapter 的辅助方法:

public TileAdapter(Context c) {
        mContext = c;
    }

    @Override
    public int getCount() {
        return 225;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        int colWidth = ((GameGrid)parent).getColumnWidth();
        if (convertView == null) {
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(colWidth , colWidth));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(0, 0, 0, 0);
        }
        else {
            imageView = (ImageView)convertView;
        }
        imageView.setImageResource(R.drawable.tile);
        return imageView;
    }

I have an android gridview which i'm using some custom scrolling going on in, to let it scroll in two dimensions - this means that the default scrolling isn't called.

I suspect this may be the reason that the rows that are off-screen are invisible. I know they're there, they affect the layout and everything, but they never draw.

So my question is this - is there any way to force the gridview to draw all of its tiles when it's loaded, and not just the visible ones?

Thanks.

Edit: To clarify - In my tileadapter, i set the child count to exactly 225. In my gridview, a call to getChildCount() returns 165.

Edit again: This only happens when the height of the gridview is greater than that of the screen - the children that are off-screen on the y axis are simply subtracted from the childcount - setting the size of the children to a number where they all fit snugly on screen removes the problem, but kills the purpose of scrolling.

Code!

XML Layout of activity:

  <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:theme="@style/Theme.Custom"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <TextView android:id="@+id/logmessage"
  android:theme="@style/Theme.Custom"
  android:layout_width="fill_parent"
  android:layout_height="25dip"
  android:text="LogMessage"/>

  <RelativeLayout android:id="@+id/boardwrap"
  android:layout_weight="1"
  android:layout_height="fill_parent"
  android:layout_width="fill_parent"
  android:gravity="center_vertical">
  <com.MyProject.GameGrid 
    android:id="@+id/board"
    android:theme="@style/Theme.Custom"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:numColumns="15"
    android:stretchMode="none"
    android:verticalSpacing="0dip"
    android:horizontalSpacing="0dip"
    android:padding="0dip"
    android:columnWidth="20dip"
    android:scrollbars="none"/>
</RelativeLayout>
<RelativeLayout 
    android:id="@+id/toolbar"
    android:layout_width="fill_parent"
    android:layout_height="60dip"
    android:background="#FFFFFFFF"/>
</LinearLayout>

Activity:

public class GameBoardActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gameboard);

        GameGrid Board = (GameGrid)findViewById(R.id.board);
        Board.setAdapter(new TileAdapter(this));
    }
}

GameGrid:

public GameGrid(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.setNumColumns(15);

        DisplayMetrics metrics = new DisplayMetrics();
        ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
        scale = metrics.density;
        smallSize = Math.round(20 * scale);
        largeSize = Math.round(40 * scale);

        columnwidth = largeSize;
        this.setColumnWidth(columnwidth);
        Common.DebugMessage(Float.toString(columnwidth));

    }

You may notice i'm defining a small and a large size here - double tapping the screen allows you to switch between the two.

Scrolling (what you helped me with earlier)

if (myState == TOUCH_STATE_SCROLLING) {
                    final int deltaX = (int) (mLastX - x);
                    final int deltaY = (int) (mLastY - y);
                    mLastX = x;
                    mLastY = y;

                    int xpos = this.getScrollX();
                    int ypos = this.getScrollY();

                    int maxX = (columnwidth * 15) - super.getWidth();
                    int maxY = (columnwidth * 15) - super.getHeight();

                    if (xpos + deltaX >= 0 && xpos + deltaX <= maxX && ypos + deltaY >= 0 && ypos + deltaY <= maxY )
                    {
                        this.scrollBy(deltaX, deltaY);
                    }
                    else {
                        this.scrollTo(xpos + deltaX <= 0 ? 0 : xpos + deltaX >= maxX ? maxX : xpos + deltaX,
                                      ypos + deltaY <= 0 ? 0 : ypos + deltaY >= maxY ? maxY : ypos + deltaY);
                    }
                    Common.DebugMessage(this.getChildCount());

                }

Common.DebugMessage is just a helper method for printing debug messages to LogCat

TileAdapter:

public TileAdapter(Context c) {
        mContext = c;
    }

    @Override
    public int getCount() {
        return 225;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        int colWidth = ((GameGrid)parent).getColumnWidth();
        if (convertView == null) {
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(colWidth , colWidth));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(0, 0, 0, 0);
        }
        else {
            imageView = (ImageView)convertView;
        }
        imageView.setImageResource(R.drawable.tile);
        return imageView;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

白昼 2024-12-17 00:36:35

Andreas,

如果您的问题只是 onDraw() 问题。您可以使用 GridView 中覆盖的 Draw(canvas) 轻松完成此操作。这会产生加载活动时增加处理器需求的副作用,但可以创建所需的效果。这样的重写如下:

 //This may be used in your GridView or Activity -- whichever provides the best result.
    public void draw(Canvas canvas)
    {   int _num = myGridView.getChildCount();
        for (int _i = _num; --_i >= 0; )
        {   View _child = (View)myGridView.getChildAt(_i);
            if (_child != null)
                _child.draw(canvas);
        }
    }

附加技术(编辑)

有时,重写draw()可能会产生不利影响。我们真正想做的是在对象可用时触发它们进行绘制。以类似的方式重写 invalidate() 通常会产生效果,具体取决于问题所在。由于我们已经确定我们通过重写 draw() 得到了奇怪的结果,这似乎是下一步的行动。

//This definitely goes in your GridView
public void invalidate()
{   int _num = myGridView.getChildCount();
    for (int _i = _num; --_i >= 0; )
    {   View _child = (View)myGridView.getChildAt(_i);
        if (_child != null)
            _child.invalidate();
    }
}

必须理解的是,这种技术可能不会在您需要时强制绘制,而只是让操作系统知道它已准备好在可用时重新绘制。由于失效不会自动沿 View 树向下级联,因此,如果您的 ImageView 嵌套得比 GridView 更深,则必须进行调整。它可以与draw()结合使用或独立使用。此外,当与 invalidate() 语句的适当位置一起使用时,可能会降低响应,但应该有助于保持图像的绘制。

该问题可能只是延迟布局或绘制问题。如果是这种情况,延迟加载解决方案可能是最好的。惰性加载器是一种在需要时加载内容的方法,因此它通常使用较少的内存和处理,并在需要时显示需要的内容。现在我不太擅长延迟加载,因为我很少有需要。但是此站点上有一个很棒的代码示例。它也是为 GridView 量身定制的。

被认为不适用(但可能对其他人有用)

我认为可能的唯一其他类型的问题是内存不足问题,不会导致强制关闭(是的,它们会导致强制关闭)存在)。这些特别难以捉摸并且照顾起来很痛苦。发现这些问题的唯一方法是在加载或滚动期间在 LogCat 中选择错误视图。或者,您可以浏览整个 LogCat 转储(我建议先清除日志,然后再运行应用程序)。

面对此类问题,了解图像的生命周期如何工作变得很重要。如果您的图像被缩小到缩略图大小以便显示,我会考虑在全尺寸图像旁边制作真实的缩略图。因为在运行时暂时缩小图像比保持原始大小需要更多的内存。由于这一切都是一次性发生的,因此这可能是一个暂时的问题,但会永久显现出来。这将大大降低内存需求。 (例如,2x2 图像需要 16 字节加上标头,而 4x4 图像需要 64 字节加上标头 [400% 为双倍大小!!]。)

此外,将 System.gc() 添加到关键位置您的代码将强制进行垃圾回收,从而更频繁地释放更多内存。 (这并不能保证释放内存,但经常有效)。

最好的解决方案可能是所有三个的组合,但需要比我们在这个问题上拥有的更多信息。例如,我们需要查看您是否覆盖了 draw()onMeasure()onLayout() 以及其他一些细节。

Andreas,

If your issue is simply an onDraw() issue. You may do so quite easily with an overridden Draw(canvas) in your GridView. This has the side effect of increasing processor requirement while your Activity is loaded, but can create the desired effect. Such an override would be as follows:

 //This may be used in your GridView or Activity -- whichever provides the best result.
    public void draw(Canvas canvas)
    {   int _num = myGridView.getChildCount();
        for (int _i = _num; --_i >= 0; )
        {   View _child = (View)myGridView.getChildAt(_i);
            if (_child != null)
                _child.draw(canvas);
        }
    }

An Additional Technique (EDIT)

Sometimes overriding the draw() can have adverse effects. What we're really trying to do is trigger the objects to draw when they are available to. Overriding invalidate() in a similar manner can often have an effect depending on where the issue lies. Since we've established that we are getting strange results with overriding draw(), this seems to be the next course of action.

//This definitely goes in your GridView
public void invalidate()
{   int _num = myGridView.getChildCount();
    for (int _i = _num; --_i >= 0; )
    {   View _child = (View)myGridView.getChildAt(_i);
        if (_child != null)
            _child.invalidate();
    }
}

It has to be understood that this technique may not force a draw when you want, but merely lets the OS know that it is ready to be redrawn when it is available. Because invalidation does not automatically cascade down the View tree, if your ImageViews are nested deeper than the GridView you will have to adjust. This can be used in conjunction with the draw() or independantly. Additionally, when used with the appropriate placement of an invalidate() statement, may lower response but should help to keep your images drawn.

The issue may simply be a delayed layout or draw issue. If that is the case, a Lazy Loading solution might be best. A lazy loader is a way to load the content when it is needed, so that it typically uses less memory, and processing, and shows what is needed, when it is needed. Now I'm not awesome at Lazy Loading because I rarely have the need. But there is a GREAT example of code at this site. It is tailored for a GridView, as well.

Deemed Not Applicable (but may be useful for others)

The only other kind of issue that I think it may be is an Out of Memory issue that isn't causing a Force Close (and yes, they do exist). These are especially elusive and painful to take care of. The only way to spot these is in your LogCat during the load or scroll, with the error view selected. Or you can go through an entire LogCat dump (I recommend clearing the Log before you run your app first).

With this kind of issue, it becomes important to know how the lifecycle of an image works. If your images are being shrunk to thumbnail size in order to display, I would consider making real thumbnails alongside the fullsize images. Because shrinking an image in runtime temporarily requires more memory than keeping it the original size. Since this is all happening in one fell sweep, this may be a temporary problem, exhibiting itself permanently. This will dramatically lower memory requirements. (As a for instance, a 2x2 image requires 16 Bytes plus the Header, whereas a 4x4 image requires 64 Bytes plus the Header [400% for double the size!!].)

Additionally, adding System.gc() to critical places in your code will force a garbage collection, freeing up more memory, more often. (This is not a guarantee to free memory, but works more often than it doesn't).

The BEST solution would probably be a combination of all three, but would require a little more information than what we have with this question. For instance, we would need to see if you have overridden draw() and onMeasure() and onLayout() and maybe some other details.

少女情怀诗 2024-12-17 00:36:35

老实说,我的建议是停止以显然不适合使用的方式对平台 API 进行攻击。即使通过一些扭曲,您成功地使用基本 GridView 代码玩了足够多的游戏,使其完成您想做的事情...您对代码将继续与 GridView 实现作为平台的细微更改一起工作有多大信心?进化。

事实上,根本没有必要玩这类游戏。 GridView 没有什么特别的——它只是一个视图的实现,将内容放入可以水平滚动的网格中?

如果 GridView 的行为不是您想要的,解决方案是编写您自己的视图来执行您想要的操作。对于 Android,这甚至更容易,因为您可以直接从开源平台获取 GridView 代码作为基础,在您的应用程序中进行编译(您可能需要调整一些东西,因为现有的代码需要不需要纯粹针对 SDK 编写,所以可能不是......但是它所做的事情没有是您在针对 SDK 的常规应用程序构建中无法做到的),并且然后根据您的喜好修改应用程序中的代码,以使它做想做的事。无需与实际上无法执行您想要的操作的内置小部件进行斗争。如果将来底层 GridView 实现发生变化,您不必担心精心构建的纸牌屋会倒塌。

Honestly, my suggestion is to stop whacking on a platform API in a way that it is clearly not intended to be used. Even if through some contortions you managed to play enough games with the base GridView code to make it do what you want to do... how confident are you that your code will continue to work with the slightly changes to the GridView implementation as the platform evolves.

And really there is just no need to play these kinds of games. There is nothing special about GridView -- it is just an implementation of a view that puts things in a grid that you can scroll horizontally through?

If GridView's behavior is not what you want, the solution is to write your own view that does what you want. And with Android this is even easier because you can just go and take the GridView code from the open-source platform as a basis, get that compiling in your app (you will probably need to tweak a few things because the code as it stands takes doesn't need to be written purely against the SDK so probably isn't... but there is nothing it is doing that you can't do in a regular app build against the SDK), and then modify that code in your app to your heart's content, to make it do what want. Without fighting with a built-in widget that doesn't actually do what you want. And without fear of your carefully constructed house of cards collapsing on you if the underlying GridView implementation changes in the future.

他不在意 2024-12-17 00:36:35

我已经提交了另一个答案,因为经过澄清后,这个问题肯定与我最初认为的不同。但是,不应忘记上一个答案中的技术,并且它们是其他相关问题的重要资源,因此我将其保留在那里。

问题:

GridView 现在可以绘制(有点),但是一遍又一遍地重复相同的图像,从而导致可怕的伪像。由此产生的伪像非常糟糕,以至于它并没有真正给出关于其他视图是否存在的良好指示。这个问题其实是“透明度太高”的问题造成的。

Android 和透明度

Android 在处理透明度方面做得非常出色,允许在顶部 视图处于焦点状态时绘制当前视图下方的对象。但是,如果所有视图都是透明的,那么当 Android 需要刷新时,就没有什么可以在所有内容后面绘制。通常,这不是问题。

一般来说,开发人员使用我们提供的工具,并尝试用它们来实现一些巧妙的事情。 (是的!)只要我们使用它们,Android 就会(几乎)说“我知道该怎么做!!”然而,当我们开始使用自定义视图时,Android 可能会有点害怕,尤其是在适当绘制时。

您的 GridView 实际上并不是 GridView。它是一个扩展GridView。作为 Android 视图的扩展,Android 不会假设它应该如何绘制,所以......因此,您的 GridView 的正常不透明背景不存在。人们可能会想,“但是我把它放在 RelativeLayout 中。这还不够吗?” 答案是否定的。布局对象就是布局对象。除非我们指定他们,否则他们没有背景。

当您进行滚动和其他类似的动作或动画时,这种情况会变得更加严重。在这些情况下,Android 会尝试缓存。缓存发生在所有视图下方,但结果是,由于它是透明的,所以您可以看到整个过程。在需要清除缓存之前它不会重置。这就是为什么它变得越来越丑陋。

换句话说,“窗口”可能显示为黑色,但实际上并不是黑色...

解决方案(第一部分):

因此答案是为扩展的 GridView 设置不透明背景 或其父视图之一。这应该可以解决您在滚动时看到的伪像。它应该允许您正确地看到其他视图如何以及是否正在渲染。最终,您想要尝试将背景应用到包含所有视图的最顶层视图。背景可以像设置背景颜色一样简单(因为它创建了一个不透明的可绘制对象)。

后续步骤:

我注意到您省略了一些相关代码。我真的需要知道你的 TileAdapter 扩展了什么样的 Adapter 以及它如何获取其基本信息。这可能会影响它如何获得和占用抽签事件。一旦我们知道了这一点,我们就可以致力于解决其余问题。

我还需要知道你如何定位瓷砖(没有定位代码)。由于没有定位代码,因此无法知道 View 是否真正被添加。 ImageView 的默认行为是,如果它们的至少一部分不可见,则在可见之前不会将它们添加到层次结构中。我们想要强制解决这个问题。

最终结果可能仍然需要调整布局、测量或绘图,但在我们获得正在发生的情况的准确表示之前我们不会知道。

另一种结果

,我希望滚动游戏更常见的是,如果它们以缩小的位置开始,而我们可以“移动”到放大的位置。可以轻松解析您的 ChildCount,正如您所说,如果它完全适合屏幕,它们都会绘制。初始放大可能会在所有内容全部加载后发生。然后你就会看到一个漂亮的图形效果,表明加载已完成。缩小只是一个普通的动画,很容易实现。你知道你所有的孩子都满载而归。此外,它可能会限制您必须输入的代码才能使其正常工作。最后,这一切都可以使用同一个 GameGrid 对象来完成。 :)

我不知道你是否考虑过这一点,但我想,“嘿,这似乎是用一块石头杀死两只以上鸟的简单方法。”

I've submitted another answer instead because after clarification, the issue is definitely different from what I initially believed. The techniques in the previous answer should not be forgotten, however, and are a great resource for other related issues, so I'm keeping it there.

Problem:

The GridView now draws (kinda), but is repeating the same images over and over again, resulting in horrible artifacts. The resulting artifacts are so bad, that it doesn't really give a good indication as to whether the other views are even present. This issue is actually caused by an issue with "too much transparency".

Android and Transparency

Android does a wonderful job handling transparency, allowing objects below the current view to be drawn while the top view is in focus. However, if all of the Views are transparent, then there is nothing for Android to draw behind everything when it needs to refresh. Ordinarily, this is not an issue.

Generally, developers use the tools provided us and just try and make some neat things happen with them. (YAY!) And as long as we use them, Android says (pretty much) "I know what to do!!" When we begin with custom Views, however, Android can get a little freaked out, especially when it comes to drawing appropriately.

Your GridView is not actually a GridView. It is an extended GridView. As an extension of an Android View, Android makes no assumptions about how it should be drawn, soooo.... As a result, the normal opaque background for your GridView does not exist. One would think, "but I have it in a RelativeLayout. Isn't that enough?" The answer is no. Layout objects are Layout objects. They have no background unless we specify them.

This becomes exacerbated when you do Scrolling and other similar movements or animations. In these cases, Android tries to cache. The caching happens kind of below all of the Views, but the result is that since it is all transparent, you see the whole process. And it doesn't reset until it needs to clear the cache. This is why is gets uglier and uglier.

In other words, the "Window" may appear black, but is not actually black...

Solution (Part I):

So the answer is to set an opaque background to either the extended GridView or to one of its parent Views. This should resolve the artifacts you are seeing when you scroll. And it should allow you to see properly how and if the other views are rendering. Ultimately, you want to try and apply the background to the topmost View that encompasses all Views. The background can be as simple as setting the background color (as it creates an opaque drawable).

Next Steps:

I've noticed you have omitted some pertinent code. I really need to know what kind of Adapter your TileAdapter extends and how it gets its base information. This can have an impact on how it is gaining and appropriating the draw events. Once we know that, we can work on fixing the rest.

I also need to know how you are positioning the Tiles (there is no positioning code). Since there is not positioning code, there is no way to know whether the Views are actually being added. The default behavior for ImageViews is that if at least some part of them aren't visible, they don't get added to the hierarchy until they are. We want to force that issue

The end result may still require adjusting layout, measures or draws, but we won't know until we get an accurate representation of what is happening.

An Alternative Result

Something, I wish happened with scrolling games more often is if they started with a zoomed out position and we could "move" to the zoomed in position.. This could easily resolve your ChildCount, as you said if it fits neatly on the screen, they all draw. And the initial zooming in could happen after everything is all loaded. Then you have a nice graphical effect indicating load is complete. A Zoom out is just a normal animation, so easy to implement. and you know all of your children are loaded. Additionally, it may limit the code you have to enter in order to get it working correctly. Finally, it can all be done with the same GameGrid object. :)

I don't know if you thought about this, but I figured, "hey, this seems like the easy way to kill more than 2 birds with one stone."

小…楫夜泊 2024-12-17 00:36:35

覆盖适配器的 getCount() 并返回适配器底层数组的长度。然后使用 mAdapter.getCount 而不是 mGrid.getChildCount。 getChildCount 仅返回可见的子项,而 getCount 将为您提供数据集中的总子项。

override getCount() of your adapter and return the length of underlying array for your adapter.And then use mAdapter.getCount instead of mGrid.getChildCount. getChildCount returns only the visible children whereas, getCount would give you total children in your dataset.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文