具有自定义视图的Android网格视图

时间:2016-04-06 22:55:28

标签: android

我是新的Android开发但是我已经在iOS中使用UICollectionView实现了附加图像但是我想知道是否可以在android中实现相同的。

我已经对网格视图以及“包含”标记进行了一些初步研究。

可以显示或隐藏图块,具体取决于存储在其他位置的变量。

我正走在正确的轨道上吗?

enter image description here

1 个答案:

答案 0 :(得分:1)

  1. 您需要一个RecyclerView。这将允许您有一个列表。请查看this教程了解详情
  2. RecyclerView的每一行都可以有以下结构

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <TextView
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:layout_weight="1"/>
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent">
                <Button 
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"/>
                <Button
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"/>
    
            </LinearLayout>
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </LinearLayout>
    
    </LinearLayout>