【问题标题】:How to create AsymmetricGridView with different image sizes in row如何在行中创建具有不同图像大小的 AsymmetricGridView
【发布时间】:2016-07-09 23:21:16
【问题描述】:

我做了很多谷歌,发现了很多例子,也探索了,但是~我想要AsymmetricGridView我的网格中不同的图像数量和不同的图像大小。

请在下面找到我对网格的要求的附加图片!

请帮助我处理这种类型的网格,或者建议我使用这种类型的不对称网格的库。

提前致谢。

【问题讨论】:

  • 你好@Arvind...你有没有解决你的问题...请告诉我..因为我也遇到了这个问题..谢谢

标签: android gridview android-gridview


【解决方案1】:

【讨论】:

  • 我试过了,但根据我的问题,第二行和第三行在这个库中是不可能的。
  • 看看库截图,是不是和你发的图一样
  • 不,看我的第一行和上面这张图是一样的,但是第二行有一个小图和一个大图,第三行只有一个图
  • 我们只提供想法,而不是完全满足您的项目要求
  • 我已经设置了 setRequestedColumnCount(3);..如果行中有一个图像,它会显示该行的绿色背景。我没有在任何地方设置绿色背景。为什么会这样,我怎么能删除它?
【解决方案2】:

您可以使用THIS LIBRARY 来实现您的目标。如果您使用的是 Android Studio,请将此库导入您的 Eclipse 工作区或包含在您的 gradle 中

在您的 build.gradle 文件中:

dependencies {
    compile 'com.felipecsl.asymmetricgridview:library:2.0.1'
}

在您的布局 xml 中:

<com.felipecsl.asymmetricgridview.library.widget.AsymmetricGridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

在你的活动课上:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    listView = (AsymmetricGridView) findViewById(R.id.listView);

    // Choose your own preferred column width
    listView.setRequestedColumnWidth(Utils.dpToPx(this, 120));
    final List<AsymmetricItem> items = new ArrayList<>();

    // initialize your items array
    adapter = new ListAdapter(this, listView, items);
    AsymmetricGridViewAdapter asymmetricAdapter =
        new AsymmetricGridViewAdapter<>(this, listView, adapter);
    listView.setAdapter(asymmetricAdapter);
}

【讨论】:

  • 我试过了,但根据我的问题第二行和第三行在这个库中是不可能的。你能告诉我这件事根据我的要求是可能的
  • 我在 github 上看到了这个库,这正是我所需要的,但我无法了解如何使用他的库来加载动态图像。在我的项目中,图像是从服务器获取的。所以我正在从服务器获取图像的 url。我可以将它们存储在列表中,但是如何使用 AsymmetricGridView 来实现它。你可以帮我解决这个问题-stackoverflow.com/questions/31792625/…
  • @BhuvneshVarma。如果您仔细分析该库并看到 AsymmetricGridViewAdapter 扩展了 BaseAdapter。所以它就像一个普通的 GridView。只需获取您的数据,将其传递给您的适配器并使用图像加载库,例如 Picasso (square.github.io/picasso) 在图像视图中加载您的项目。
  • @BhuvneshVarma 好吧,我没有特别使用这个库。但是你能发布一些图片或其他东西来澄清它吗?
  • 我也尝试过这个库,但它在设置 adaper.with 错误后强制关闭应用程序并出现错误 - 尝试调用接口方法 'int com.felipecsl.asymmetricgridview.library.model.AsymmetricItem.getRowSpan()'在空对象引用上。请帮忙
猜你喜欢
  • 2014-11-27
  • 1970-01-01
  • 2021-05-25
  • 1970-01-01
  • 1970-01-01
  • 2020-03-14
  • 2019-02-12
  • 1970-01-01
  • 2020-02-20
相关资源
最近更新 更多