开发者

Android Listview - first item is different

开发者 https://www.devze.com 2023-01-14 18:42 出处:网络
For some reason, the text has 0 width in the second row. Code: public LinearLayout getView(int position, View convertView, ViewGroup parent){

For some reason, the text has 0 width in the second row.

Android Listview - first item is different

Code:

public LinearLayout getView(int position, View convertView, ViewGroup parent){
    LinearLayout rowView;
    if(convertView==null){
        rowView=(LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.icon_list, null);
    }else{!
        rowView=(LinearLayout) convertView;
    }
    //Image view
    ImageView imageView=(ImageView) rowView.findViewById(R.id.list_icon);
    Pair<String,Bitmap> p=getItem(position);
    imageView.setImageBitmap(p.second);
    //Text view
    TextView textView=(TextView) rowView.findViewById(R.id.list_text);
    textView.setText("AAAA");
    return rowView;
}

XML:

<?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="20dip"
    android:id="@+id/icon_list"
    android:padding="6dip">

    <ImageView android:id="@+id/list_icon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="6dip"
        android:layout_gravity="left"/>

    <TextView android:id=开发者_Python百科"@+id/list_text"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:gravity="center_vertical"/>

</LinearLayout>

EDIT:

Before I had accidentally left in the line.

android:src="@drawable/icon"

I removed it, but the problem remains


This isn't a very good answer, but it worked well enough. I set the layout_width and layout_height of Android 45dip. This then caused everything to work properly. I still don't understand how it was allowed to ignore the android:layout_height="20dip" for the section.

0

精彩评论

暂无评论...
验证码 换一张
取 消