Android Element List Height

Why, when I use SimpleCursorAdapter for a ListView, I have the height of the elements in the ListView, like this - listview image

(My code is based on this )

But when using arrays, Listview Elements are very tall

listview big

(I am studying listview based on this )

Line layout for a list of list items

<?xml version="1.0" encoding="utf-8"?> <TextView android:id="@+id/text1" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"/> 

So my question is, why is there a difference in line heights when using ArrayAdapter and SimpleCursorAdapter?

+50
android listview android-arrayadapter row simplecursoradapter
Nov 22 '10 at 9:19
source share
7 answers
  android:textAppearance="?android:attr/textAppearanceLarge" 

seemed ineffective.

  android:minHeight="?android:attr/listPreferredItemHeight" 

changed the height for me

+122
Nov 25 '10 at 7:10
source share

The trick for me did not set the height - but instead set minHeight. This should be applied to the root view of any layout that uses a custom adapter to render each row.

+35
Sep 09 '11 at 23:19
source share

You need to use the registration in the list layout, so space is added along the edges of the element (just increasing the font size will not do this).

 <?xml version="1.0" encoding="utf-8"?> <TextView android:id="@+id/text1" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="8dp" /> 
+9
May 12 '12 at 10:29
source share

I did something like this:

 @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); TextView textView = (TextView) view.findViewById(android.R.id.text1); textView.setHeight(30); textView.setMinimumHeight(30); /*YOUR CHOICE OF COLOR*/ textView.setTextColor(Color.BLACK); return view; } 

You must place both fields textView.setHeight (30); textView.setMinimumHeight (30); or it will not change anything. It worked for me, and I had the same problem.

+4
Apr 15 '13 at 8:57
source share

The height of the list items is adjusted based on its contents. There is no content in the first image. therefore the height is very minimal. In the second image, the height increases depending on the size of the text. Because you specified android: layout_height = "wrap_content".

+1
Dec 10 '12 at 10:05
source share

This is my solution (there is a nested LinearLayout):

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/item" android:layout_width="match_parent" android:layout_height="47dp" android:background="@drawable/box_arrow_top_bg" android:gravity="center" android:text="全部收支" android:textColor="#666" android:textSize="16sp" /> </LinearLayout> </LinearLayout> 
0
Feb 18 '13 at 16:39
source share

Here are my solutions; This is my getView () in a subclass of BaseAdapter:

 public View getView(int position, View convertView, ViewGroup parent) { if(convertView==null) { convertView=inflater.inflate(R.layout.list_view, parent,false); System.out.println("In"); } convertView.setMinimumHeight(100); return convertView; } 

Here I set the minimum height of the ListItem to 100;

0
Jul 19 '16 at 16:08
source share



All Articles