从底部开始的 Android gridview 堆栈

标签 android gridview

我正在尝试创建一个由 15x20 TextView 组成的 GridView ,并且我希望 TextView 从下到上填充。例如 getChildAt(0) 将引用左下角的网格。现在它总是引用左上角的网格。 我试过了

android:stackFromBottom="true"

但它不起作用。下面是我的代码,希望有人能给我一些见解我做错了什么。谢谢!

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/sample_main_layout">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="313dp"
    android:layout_weight="0.18">

    <GridLayout
        android:id="@+id/map_grid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:columnCount="15"
        android:descendantFocusability="afterDescendants"
        android:gravity="center"
        android:horizontalSpacing="30dp"
        android:paddingLeft="20dp"
        android:rowCount="20"
        android:stackFromBottom="true"
        android:stretchMode="columnWidth"
        android:verticalSpacing="30dp">

    </GridLayout>

使用你们建议的一些解决方案,我创建了一个函数来更正我的网格索引。它将从最后一个位置引用网格。

编辑:

   public int correctIndex(int index) {
    int mul = (int) Math.floor(index /15);
    int remainder = index%15;
    remainder = 15-remainder;
    int correctedIndex = 300-(mul*15+remainder);
    return correctedIndex;
   }

最佳答案

您不需要以相反的顺序填充GridView。您只需要以相反的顺序读取它即可。

代替:

gridView.getChildAt(position);

使用:

gridView.getChildAt(gridView.getChildCount() - position - 1);

当然,你应该用你正在使用的变量替换位置 - 1

关于从底部开始的 Android gridview 堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46611824/

相关文章:

android - 以编程方式读取 list 文件?

jquery - Asp.net Obout grid,如何使用其内置功能在不刷新页面的情况下发布数据?

c# - 在不更改边框颜色的情况下更改 GridView 单元格中文本的颜色

asp.net - 如何在运行时使用 AutoGenerate ="True"更改 GridView 上的字段类型?

android - 如何在 Android 中将网格线设置为 GridView

android - 冲突的内容提供者 facebook SDK

android - 限制 TextView 的长度

Android TV RecyclerView焦点交互

c# - 使用 split 函数创建二维数组列表并绑定(bind)到 asp.net c# 中的 gridview

android - android 中 epub 的 webview 不显示图像