【问题标题】:How I Create a GridView Inside a Fragment in Android Studio如何在 Android Studio 的片段中创建 GridView
【发布时间】:2015-10-29 02:43:37
【问题描述】:

我是 Android 新手,但知道最基本的知识。我想创建一个自定义 GridView,就像显示的 spotify 浏览页面一样,但在 Fragment Tab 内。我在网上搜索过,但在活动页面上只找到了 gridview 教程。但我想在fragment Tab 上实现我的。

如果我可以让每个网格项目使用某种点击监听器打开一个新页面,那就太棒了。

到目前为止,我已经创建了

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<GridView
    android:numColumns="auto_fit"
    android:gravity="center"
    android:columnWidth="90dp"
    android:stretchMode="columnWidth"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/form_grid"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    />

</LinearLayout>

支持gridview的标签xml。

下面是 grid_row.xml 布局本身

< FrameLayout xmlns: android = "http://schemas.android.com/apk/res/android"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: orientation = "vertical" >

  < ImageView
android: id = "@+id/grid_image"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_gravity = "top" / >

  < TextView
android: id = "@+id/grid_label"
android: layout_width = "fill_parent"
android: layout_height = "45dp"
android: layout_marginTop = "175dp"
android: background = "@drawable/ic_header_logo"
android: gravity = "center"
android: textColor = "#FFFFFF"
android: textSize = "12sp"
android: textStyle = "bold" / >
  < /FrameLayout>

【问题讨论】:

    标签: java android android-fragments gridview android-studio


    【解决方案1】:

    我还遇到了在 Android Studio 中使用多个“布局”的问题,在这种情况下,片段也算作布局,我建议您手动编写布局,然后切换到图形界面。

    EDIT在里面使用一个线性布局和一个gridview....见cmets

    【讨论】:

    • 我刚刚重新编辑了这个问题。在我的情况下,我不确定“view”的答案,我的 tab.xml 片段包含 gridview。但我确定我需要一个基本适配器之类的东西。任何我不怎么使用图形界面的地方
    • 我也是.... 错误。你只在linearlayout中使用gridview吗?如果是这样,为什么不删除线性布局并将gridview更改为gridlayout
    • 哇。我明白了所以更像是我应该取消 LinearLayout 父级,然后使用 gridview 它自己开始 xml
    • 抱歉,我是新人。当您在 Gridview 上方说 GridLayout 时,它有点令人困惑,因为片段本身就是一个视图。?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 2020-12-25
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 2020-02-29
    相关资源
    最近更新 更多