2017-02-13 2 views
0

У меня проблема с установкой моих изображений в gridview в Android Studio. В основном мне нужно иметь 2 изображения на строку и прокручивать вниз с помощью TextViews на изображениях, но когда я прокручиваю назад или вниз, изображения меняют позиции, чтобы склеить их. У них разные размеры в исходном формате. Вот мое изображение макета item_district.xml:Android Gridview, изображения не подходят

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="1"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/photo" 
     android:scaleType="fitCenter" 
     android:adjustViewBounds="true" 
     android:layout_margin="2dp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     android:textSize="10dp" 
     android:id="@+id/hoverText"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:textSize="64dp" 
     android:id="@+id/hoverId"/> 

</RelativeLayout> 

GridView расположение activity_district.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_district" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="iut.paci.noelcommunity.DistrictActivity"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/textView3"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/editAddress" 
      android:hint="Your address ..." 
      /> 

     <GridView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/grid" 
      android:numColumns="auto_fit" 
      android:columnWidth="150dp" 
      android:stretchMode="columnWidth" 
      android:gravity="center"/> 
    </LinearLayout> 

</RelativeLayout> 

Спасибо за вашу помощь!

+0

Изменить масштаб Тип в xml: android: scaleType = "fitXy" –

ответ

0

Эта проблема возникает из-за того, что высота элемента сетки зависит от ее содержимого, то есть изображение и просмотр изображений ур не синхронизируются с вашим видом переработанной сетки. Одним из простых исправлений является исправление высоты элементов сетки. Примените высоту к относительной компоновке элемента сетки. Рекомендуется использовать одинаковые размеры в gridview для лучшего пользовательского интерфейса.

+0

Спасибо! Работал отлично :) –

Смежные вопросы