【问题标题】:GridView item height is mismatched with otherGridView 项目高度与其他不匹配
【发布时间】:2018-10-24 21:26:56
【问题描述】:

我正在使用网格视图。它在某些设备中显示问题。网格视图中的一项看起来比其他项的高度要短。

在某些设备上看起来像这样,而在某些设备上则很好。

布局:

    <?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>

如何管理每个项目的高度?解决方案是什么?请帮忙。谢谢...

【问题讨论】:

  • 使文本单行为真或固定文本和图像的高度,否则如果文本和图像高度增加,网格高度会改变。
  • 请分享gridview项目代码
  • 请同时提供您的 gridview 项目的代码
  • 你的应用看起来就像一个管理用户现金流的应用。因此,您正在为您所在地区的一家现有银行制作应用程序?请问您打算如何处理用户凭据?您将需要他们访问他们在银行服务器上的帐户,不是吗?
  • 我已添加项目布局,请检查。 @PoovarasanSelvaraj

标签: java android xml android-gridview datagridviewcolumn


【解决方案1】:

Gridview 倾向于调整具有最高元素的所有元素的高度。因此,您会看到这种行为。您可以使用 StaggeredGridView。

【讨论】:

    【解决方案2】:

    我认为您的网格布局单元格高度是 wrap_content。这个问题同样发生在我身上。将布局高度 wrap_content 更改为 ma​​tch_parent

     android:layout_height="match_parent"
    

    为获得更好的解决方案,请在此处更新您的网格视图项目布局单元格。

    【讨论】:

    • 还添加了项目布局请检查
    【解决方案3】:

    添加 Textview 属性:

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

    如果文本单行不可见,则需要将 textview 更改为 autosizing-textview

    enter link description here

    【讨论】:

      猜你喜欢
      • 2014-08-03
      • 1970-01-01
      • 2015-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-25
      • 2016-07-16
      • 2012-08-18
      相关资源
      最近更新 更多