我如何在Android Studio中的片段中创建GridView

时间:2015-08-06 05:30:15

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

我是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布局本身

&#13;
&#13;
< 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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

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

编辑在里面使用linearlayout和gridview ....参见评论