Высота элемента GridView не соответствует другим - PullRequest
0 голосов
/ 15 мая 2018

Я использую сетку.Это показывает проблему в некоторых устройствах.Один элемент вида сетки выглядит короче по высоте, чем другие.

enter image description here

На некоторых устройствах это выглядит так, а на некоторых - нормально.

Макет:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:background="@android:color/white"
        android:layout_height="match_parent">

    </RelativeLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">
<LinearLayout android:orientation="vertical"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.admin.fueloneApp.MainDriver"
    tools:showIn="@layout/app_bar_main"
    android:weightSum="8">


    <TextView
        android:id="@+id/main_welcome"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/dimen_20dp"
        android:text="@string/welcome"
        android:textColor="@color/colorPrimary"
        android:textStyle="bold" />

    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gridviewMain"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="@dimen/dimen_40dp"
        android:layout_marginLeft="@dimen/dimen_40dp"
        android:layout_marginRight="@dimen/dimen_40dp"
        android:columnWidth="80dp"
        android:horizontalSpacing="@dimen/dimen_10dp"
        android:numColumns="2"
        android:stretchMode="columnWidth"
        android:verticalSpacing="10dp"></GridView>

</LinearLayout>


    </ScrollView>

    <TextView
        android:id="@+id/textView20"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="false"
        android:text="For Any Queries Related To Mobile App Click On Service Request"
        android:textAlignment="center" />

</RelativeLayout>

Макет элемента

РЕДАКТИРОВАТЬ: Добавлен макет элемента в виде сетки.

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/single_grid"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary1"
    android:orientation="vertical">
   <ImageView
       android:id="@+id/gris_img"
       android:layout_gravity="center"
       android:layout_width="80dp"
       android:scaleType="fitXY"
       android:layout_height="100dp" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/grid_cat"
            android:textSize="15sp"
            android:textColor="@color/divider_color"
            android:gravity="center"/>

</LinearLayout>

Как управлять высотой каждого элементавещь?Какое решение для этого?Пожалуйста помоги.спасибо ...

Ответы [ 3 ]

0 голосов
/ 15 мая 2018

Я думаю, что ваша высота ячейки сетки составляет wrap_content . эта проблема же происходит со мной. изменить высоту макета wrap_content на match_parent .

 android:layout_height="match_parent"

для лучшего решения, пожалуйста, обновите ячейку макета элемента вида сетки здесь.

0 голосов
/ 15 мая 2018

Добавить свойство Textview:

android:maxLines="1"    
android:singleLine="true"

если текст не виден в одной строке, вам нужно изменить textview на autosizing-textview

введите описание ссылки здесь

0 голосов
/ 15 мая 2018

Gridview имеет тенденцию регулировать высоту всех элементов с самым высоким элементом из всех.Отсюда и такое поведение. Вы можете использовать StaggeredGridView.

...