【问题标题】:Change ListView layout to cells layout将 ListView 布局更改为单元格布局
【发布时间】:2017-01-08 20:52:33
【问题描述】:

我的 Android 应用中有一个 ListViewListView 应该是项目目录。现在,它看起来不太像目录,因为它显示为行列表。

有没有办法创建某种表格视图,其中包含 3 个垂直行和与目录中的项目数一样多的水平行,并且仍然使用我在 ListView 中使用的相同数据?另外,如何将单元格布局更改为矩形单元格?

CellLayout.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/itemNameList"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/itemPriceList"
    android:layout_below="@+id/itemNameList"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"/>

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/itemImageList"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

【问题讨论】:

  • 很确定你想要一个带有 GridLayoutManager 的 GridView 或 RecyclerView。 ListView 只会做一个垂直的项目堆栈。
  • 是的,但是我怎样才能改变它,并且仍然使用我的BaseAdapter

标签: android android-layout listview catalog xmlcatalog


【解决方案1】:

我用一个非常简单的方法解决了这个问题:我刚刚将ListView 的类型更改为GridView 并固定了单元格布局,因此它将垂直显示而不是水平显示。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-26
    • 2016-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多