代码之家  ›  专栏  ›  技术社区  ›  Devrath

在android中查看图片的简单GridView

  •  1
  • Devrath  · 技术社区  · 11 年前

    我有GridView,它显示JSON中的图像

    [图像]

    enter image description here

    我的网格视图xml是 ::

    餐厅desc_photos.xml

    <?xml version="1.0" encoding="utf-8"?>
    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/listview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:numColumns="auto_fit"
        android:columnWidth="90dp"
        android:horizontalSpacing="10dp"
        android:verticalSpacing="10dp"
        android:gravity="center"
        android:stretchMode="columnWidth" >  
    
    </GridView>
    

    网格视图图像.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" >
    
        <ImageView
            android:id="@+id/flag"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:background="#000000"
            android:padding="1dp" />
    
    </RelativeLayout>
    

    如何进行更改,以便将我的输出反映为:

    enter image description here

    水平滚动在这里也很重要

    任何想法

    谢谢

    1 回复  |  直到 11 年前
        1
  •  1
  •   Swapnil Kadam    11 年前

    唯一的方法是使用双向网格视图库使用以下库链接 https://github.com/jess-anders/two-way-gridview

    1) 将该库添加到项目中

    2) 在将插入水平滚动视图的xml布局中相应地更改包名称 片段:

       <com.future.android.app.library.slidinggridview.TwoWayGridView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@id/fragment_product_twgv_grid"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="5dp"
        android:visibility="gone"
        app:cacheColorHint="#ffe8e8e8"
        app:columnWidth="300dp"
        app:horizontalSpacing="10.0dip"
        app:numColumns="auto_fit"
        app:numRows="2"
        app:rowHeight="290dp"
        android:fastScrollEnabled="true"
        app:scrollDirectionLandscape="horizontal"
        app:scrollDirectionPortrait="vertical"
        app:stretchMode="spacingWidthUniform"
        app:verticalSpacing="10.0dip" />
    

    您可以相应地设置列数以及宽度和高度。