簡體   English   中英

Android GridView文本重疊

[英]Android GridView Text overlapping

我現在嘗試了兩天來創建一個可運行的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>

我要解決的想法是在一個行中獲取最長視圖的高度,然后將其設置為最后一個視圖的MinHeight。 我的問題是,僅在可見時保存視圖,因此上下滾動的高度又一次不同。 有誰知道如何解決這個問題?

另一個解決方案是將單元格的父級保留為wrap_content,但將TextView限制為例如2或3行android:lines="2" ,則網格視圖中的所有視圖將具有相同的大小。

您的問題在於gridViewItem布局(您在適配器中充氣的布局)而不是gridview,我相信它有

android:layout_height="wrap_content" 

在某處,只需將布局高度設置為固定的dp

(android:layout_height ="10dp" for instance) 

這樣您就不會有問題。

根據評論進行編輯: 2個選項-1)如果列表不是很長,則只需使用tableLayout並在代碼中填充行(減去的是它沒有Recicle視圖,因此比gridview占用更多的內存),但應該可以達到效果想要(每行使用自動換行內容並調整為文本長度)

2)適配器正在使用某種列表-在使用網格之前運行它並獲取最大高度,現在創建一個自定義適配器,該適配器使用getView()中的那個(最大高度)返回正確的視圖(所有足夠大以達到最大長度)

我認為,以下網址描述了一種解決方案: http : //obduro.nl/blog/the-solution-of-android-gridview-overlap/

在以下位置報告了該錯誤: https : //code.google.com/p/android/issues/detail?id=75766

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM