2017-02-19 39 views
0

我想使用圖像單元格來顯示一些圖像集合在我的應用程序內顯示一些圖像集合在主列表中查看代碼工作正常,圖像顯示在列表視圖中,但問題是所有單元格只顯示2個圖像(我已經在gridview佈局中指定了2個列),而我已經填充了5個圖像的GridView列表!GridView作爲列表視圖單元格不顯示所有項目

她是我的佈局:

主要的ListView,

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="com.mtids.gridviewaslistviewcell.MainActivity"> 

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/LV" /> 
</LinearLayout> 

和GridView的佈局,

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <GridView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:numColumns="2" 
     android:scrollbars="vertical" 
     android:verticalSpacing="10dp" 
     android:horizontalSpacing="10dp" 
     android:id="@+id/cgrid" /> 
</LinearLayout> 

和ImageView的單元佈局,

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_width="150dp" 
     android:layout_height="150dp" 
     app:srcCompat="@mipmap/ic_launcher" 
     android:id="@+id/cimage" /> 
</LinearLayout> 

任何想法會很多ppreciated

enter image description here

+0

您是否嘗試從網格視圖中刪除numColumns? –

+0

你可以參考這個網址:http://stackoverflow.com/a/27353336/5860087 –

+0

仍然不能正常工作 –

回答

0

需要下面的東西使用gridview的,列表視圖 -

1)含有的GridView或ListView
2)佈局的GridView或ListViewItem的(單件) 3)適配器結合佈局數據到列表視圖或GridView

現在你可以嘗試與android:columnWidth =「任何值只要你喜歡(dp)」,android:nu mColumns =「auto_fit」,android:stretchMode =「columnWidth」在GridView上。

文檔https://developer.android.com/guide/topics/ui/layout/gridview.html

+0

也不能正常工作,問題是與細胞高度! –

相關問題