android listview item height

前端 未结 7 1696
渐次进展
渐次进展 2020-12-07 17:53

Why when i use SimpleCursorAdapter for ListView i have items height in ListView like this - \"listview

相关标签:
7条回答
  • The trick for me was not setting the height -- but instead setting the minHeight. This must be applied to the root view of whatever layout your custom adapter is using to render each row.

    0 讨论(0)
  • 2020-12-07 17:59
      android:textAppearance="?android:attr/textAppearanceLarge" 
    

    seemed no effect.

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

    changed the height for me

    0 讨论(0)
  • 2020-12-07 18:01

    The height of list view items are adjusted based on its contents. In first image, no content. so height is very minimum. In second image, height is increased based on the size of the text. Because, you specified android:layout_height="wrap_content".

    0 讨论(0)
  • 2020-12-07 18:01

    Here is my solutions; It is my getView() in BaseAdapter subclass:

    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 have set ListItem's minimum height to 100;

    0 讨论(0)
  • 2020-12-07 18:07

    You need to use padding on the list item layout so space is added on the edges of the item (just increasing the font size won't do that).

    <?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" />
    
    0 讨论(0)
  • 2020-12-07 18:11

    I did something like that :

    @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 put the both fields textView.setHeight(30); textView.setMinimumHeight(30); or it won't change anything. For me it worked & i had the same problem.

    0 讨论(0)
提交回复
热议问题