【问题标题】:Set column count and horizontal in HorizontalGridView Android在 Horizo​​ntalGridView Android 中设置列​​数和水平
【发布时间】:2016-12-26 14:51:50
【问题描述】:

当我尝试使用 android.support.v17.leanback.widget.Horizo​​ntalGridView

创建可以水平滚动的网格视图时,我遇到了标题中提到的问题

结果如下所示:

但我需要在每个项目之间留出一些空间,并且控制项目的数量会出现在屏幕上,如下所示:

我的 layout.xml 代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:orientation="vertical"
tools:context="layout.productListFragment">

<!-- TODO: Update blank fragment layout -->

<android.support.v17.leanback.widget.HorizontalGridView       xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/productListGrid"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="top"   
/>

我尝试使用下面的代码,但它似乎根本没有生效

android: android:numColumns="3"
android:columnWidth="60dp"
android:stretchMode="columnWidth"

有single_product_layout的代码

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:paddingLeft="5dp"
android:paddingRight="5dp">

<TableRow
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical">

    <ImageView
        android:id="@+id/singleProduct_image"
        android:layout_width="wrap_content"
        android:layout_height="150dp"
        android:layout_gravity="top"
        android:layout_span="2"
        android:src="@drawable/product1" />
</TableRow>

<TableRow>

    <TextView
        android:id="@+id/singleProduct_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/singleProduct_image"
        android:gravity="left"
        android:text="Tên sản phẩm"
        android:textSize="12dp"
        android:textStyle="bold" />
</TableRow>

<TableRow>

    <RatingBar
        android:id="@+id/singpleProduct_ratingBar"
        style="?android:attr/ratingBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/singleProduct_name"
        android:layout_gravity="left"
        android:layout_weight="4"
        android:numStars="5" />

    <TextView
        android:id="@+id/singleProduct_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/singleProduct_image"
        android:layout_below="@+id/singleProduct_name"
        android:layout_gravity="right"
        android:layout_weight="6"
        android:gravity="right"
        android:text="25.000VND"
        android:textColor="@color/mainThemeColor"
        android:textSize="10dp" />
</TableRow>

</TableLayout>

非常感谢

【问题讨论】:

    标签: android gridview horizontal-scrolling


    【解决方案1】:

    我今天刚刚遇到这个问题,出于某种原因,Android Studio(撰写本文时为 2.3)没有显示 HorizontalGridView(Leanback v17)的所有自动完成选项。

    你的目标是:

    android:horizontalSpacing="10dp"

    或者您可以通过编程方式进行

    gridView.setHorizontalSpacing(10)

    其中 10 是以像素为单位的间距。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-20
      • 1970-01-01
      • 2017-10-28
      相关资源
      最近更新 更多