【问题标题】:android-How gridview stretch to fill widthandroid-gridview如何拉伸以填充宽度
【发布时间】:2015-02-10 23:41:28
【问题描述】:

这是我当前的 gridview 的图像:

这就是我想要得到的:

这是我的 griview 布局:

    <GridView
    android:id="@+id/gridView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:columnWidth="100dp"
    android:drawSelectorOnTop="true"
    android:gravity="center"
    android:numColumns="2"
    android:stretchMode="spacingWidthUniform"
    android:verticalSpacing="5dp" >
</GridView>

这是我的自定义行:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical"
 >

<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitCenter" >
</ImageView>

<TextView
    android:id="@+id/text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:gravity="center"
    android:includeFontPadding="false"
    android:singleLine="true"
    android:lineSpacingExtra="5dp"
    android:textSize="12sp" >
</TextView>

我已经尝试了大约 3 个小时,但我做不到,上面的代码是我最新的代码。你可以帮帮我吗 ?如何使 2 行填充宽度?

谢谢

【问题讨论】:

标签: android android-listview android-gridview


【解决方案1】:

您需要使用 dp 将 ImageView layout_width + layout_height 从 match_parent 更改为固定大小。例如,对宽度和高度执行 60dp 之类的操作

【讨论】:

    【解决方案2】:

    您必须在数据(图像和文本)和视图(GridView)之间使用适配器:

    这里有一个很好的 CustomGrid 扩展 BaseAdapter 的例子:Android Custom GridView with Images and Text

    希望对你有帮助!

    莱昂内尔

    【讨论】:

      猜你喜欢
      • 2018-04-25
      • 1970-01-01
      • 2011-10-27
      • 1970-01-01
      • 2014-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-06
      相关资源
      最近更新 更多