修复GridView项的大小

时间:2017-05-02 20:57:47

标签: android xml gridview

我正在尝试使用图片来创建应用我遇到GridView的问题 尺寸每次都有所不同,所有图片的尺寸都相同 480x800 ,但当我scroll尺寸上下变化时,我不知道原因?

fragment.xml之

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:background="#0e0e0e"
      tools:context=".Art">
  <!-- TODO: Update blank fragment layout -->
  <GridView
    android:layout_marginTop="4dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/gridViewCategory"
    android:numColumns="2"
    android:horizontalSpacing="3dp"
    android:verticalSpacing="3dp"
    android:stretchMode="columnWidth"/>
  </LinearLayout>

picture_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   android:orientation="vertical" android:layout_width="match_parent"
   android:layout_height="match_parent">
 <ImageView
      android:background="#f6000000"
      android:layout_margin="2dp"
      android:adjustViewBounds="true"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/arrw"
      android:layout_gravity="center"
      android:id="@+id/cat_imageView" />
 </LinearLayout>

enter image description here

1 个答案:

答案 0 :(得分:0)

更新picture_item.xml,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:background="#f6000000"
        android:layout_margin="2dp"
        android:adjustViewBounds="true"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:scaleType="fitXY"
        android:src="@drawable/arrw"
        android:id="@+id/cat_imageView" />
 </LinearLayout