6

我必须使用 Gridview 创建 UI。图像是动态的,因为它来自 webservice 。

我可以使用 xml 定义列号,但是第零个索引处的项目必须有一个完整的图像,然后其余的应该分成列。

任何帮助表示赞赏。

4

4 回答 4

2

你应该使用TableLayout. GridView不支持跨越操作。

将其子项排列成行和列的布局。一个 TableLayout 由许多 TableRow 对象组成,每个对象定义一个行(实际上,您可以有其他子对象,这将在下面解释)。TableLayout 容器不会为其行、列或单元格显示边框线。每行有零个或多个单元格;每个单元格可以容纳一个 View 对象。该表的列数与单元格最多的行一样多。表格可以将单元格留空。单元格可以跨列,就像在 HTML 中一样。

你可以在这里看到一个例子。

于 2013-11-02T12:14:29.353 回答
1

基于杰克·K·福阿尼。一些将保存整个图像免于裁剪的更改:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

   <!-- Large Image   -->
    <ImageView
         android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true" />
    <!-- //Large Image -->

    <!-- Small Images -->
    <GridView 
      android:id="@+id/list"
      android:numColumns="auto_fit"
      android:columnWidth="120dip"
      android:gravity="center"
      android:layout_width="fill_parent"
      android:layout_weight="1"
      android:layout_height="0dip" >
   </GridView>
    <!-- Small Images -->

</LinearLayout>

一个快速的解决方案,其他人有很多工作,尝试一下。你可能会喜欢它。

GridView gv = findViewById(R.id.list);
        gv.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onScroll(AbsListView arg0, int firstVisibleItem, int arg2, int arg3) {
                // TODO Auto-generated method stub
                ImageView iView = findViewById(R.id.image);
                if (firstVisibleItem == 0)
                {
                    iView.setVisibility(View.VISIBLE);
                }
                else
                {
                    iView.setVisibility(View.Gone);
                }
            }
        });
于 2013-11-02T12:30:31.173 回答
0

我通过使用 ListView 解决了它。向 listView Header 添加了一个视图。然后在列表视图的子视图中,我添加了两个视图。在自定义适配器的 getView 方法中,我每次都将位置增加一。

PS:如果您想使用无限适配器实现上述视图,您将不得不找到更好的解决方案。

于 2013-11-14T04:41:10.180 回答
0

您可以使用GrideViewweight=1 及以上添加ImageView

例如,如果您想使用GrideView这是完整的示例布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

   <!-- Large Image   -->
    <ImageView
         android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dip"
        android:layout_gravity="center_horizontal"
        android:scaleType="centerCrop" />
    <!-- //Large Image -->

    <!-- Small Images -->
    <GridView 
      android:id="@+id/list"
      android:numColumns="auto_fit"
      android:columnWidth="120dip"
      android:gravity="center"
      android:layout_width="fill_parent"
      android:layout_weight="1"
      android:layout_height="0dip" >
   </GridView>
    <!-- Small Images -->

</LinearLayout>

此布局将与您的要求完全相同

在此处输入图像描述

于 2013-11-02T12:20:57.300 回答