我现在尝试了两天来创建一个可用的 GridView
,但它不起作用,它看起来是这样的:
你看,我的问题是文字重叠。
我已经发现,GridView
行的高度由最后一项设置。
我的 XML 看起来是这样的:
<RelativeLayout 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"
tools:context=".Startbildschirm">
<GridView
android:numColumns="2"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:horizontalSpacing="5dp"
android:verticalSpacing="5dp"
/>
</RelativeLayout>
我解决这个问题的想法是获取一行中最长 View 的高度,然后将其设置为最后一个 View 的 MinHeight。我的问题是,只有在 View 可见时才会保存 View ,因此在向下和向上滚动时高度再次不同。 有谁知道如何解决这个问题?
最佳答案
另一种解决方案是将单元格的父级保留为 wrap_content,但将 TextView 限制为例如 2 或 3 行 android:lines="2"
这样 GridView 中的所有 View 都将具有相同的大小。
关于java - Android GridView 文本重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27891854/