Maximize visible rows in a listview

匿名 (未验证) 提交于 2019-12-03 08:28:06

问题:

Here's my code for items in a list.. Suppose I'm inflating this TextView into the ListView

<TextView    android:id="@+id/textviewItemList"    android:layout_width="fill_parent"    android:layout_height="50dp"    android:paddingBottom="10dip"    android:paddingLeft="10dip"    android:paddingTop="10dip"    android:textSize="35px" /> 

And here is my code for ListView, inside a RelativeLayout having only 3 rows are visible with others as scrollable. RelativeLayout having height of x3 of the height of text view...

<RelativeLayout   android:layout_width="wrap_content"   android:layout_height="150dp"   android:layout_marginTop="15px"   android:background="@drawable/border"   android:layout_centerHorizontal="true"   android:orientation="vertical">     <ListView        android:id="@+id/listview_data"        android:layout_width="300px"        android:layout_height="wrap_content"        android:columnWidth="30px"        android:gravity="center"        android:numColumns="10">    </ListView> </RelativeLayout> 

But when the ListView is created with more than 3 items, I get shadow part when scrolling down or up, it didn't highlight all (it has some kind of shadow part or I say fading part)...

回答1:

Add android:cacheColorHint="#00000000" in your listview. Here's the second segment of your code rewritten with cacheColorHint:

<RelativeLayout     android:layout_width="wrap_content"     android:layout_height="150dp"     android:layout_marginTop="15px"     android:background="@drawable/border"     android:layout_centerHorizontal="true"     android:orientation="vertical">     <ListView         android:id="@+id/listview_data"         android:layout_width="300px"         android:layout_height="wrap_content"         android:columnWidth="30px"         android:gravity="center"         android:numColumns="10"         android:cacheColorHint="#00000000" >     </ListView> </RelativeLayout> 

It removes the shadow/turning the screen black problem of your ListView.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!