The cell height of the ListView cannot be adjusted.

Asked 2 years ago, Updated 2 years ago, 88 views

The cell height of the ListView cannot be adjusted.

Give android:layout_height="70dp" and it should come out at the height of the cell 70dp

It's coming out too big. I've tried minheight, shortened it, and stretched it, but there's no change.

<com.baoyz.swipemenulistview.SwipeMenuListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/inspectorListView"
        android:layout_gravity="center_horizontal" />
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:background="@drawable/bg_yellow">

    <ImageView
        android:id="@+id/thumbnail"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_gravity="left|center_vertical"
        android:layout_marginLeft="10dp" />

    <TextView
        android:id="@+id/itemInfo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center_vertical"
        android:layout_marginLeft="30dp"
        android:layout_weight="1"
        android:textSize="15dp"
        android:textColor="@color/white"/>

</LinearLayout>
private class InspectorAdapter extends ArrayAdapter {
        LayoutInflater mLayoutInflater;

        public InspectorAdapter(Context context, int resource, ArrayList<InspectorItem> list) {
            super(context, resource, list);
            mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view;
            ViewHolder viewHolder;
            if (convertView == null) {
                view = mLayoutInflater.inflate(R.layout.activity_inspector_list_item, parent, false);
                viewHolder = new ViewHolder();
                viewHolder.thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
                viewHolder.itemInfo = (TextView) view.findViewById(R.id.itemInfo);
                view.setTag(viewHolder);
            } } else {
                view = convertView;
                viewHolder = (ViewHolder) view.getTag();
            }
            InspectorItem inspectorItem = (InspectorItem) getItem(position);
            viewHolder.thumbnail.setImageResource(inspectorItem.getThumbNail());
            viewHolder.itemInfo.setText(inspectorItem.getItemInfo());
            return view;
        }
    }

    private class ViewHolder {
        private ImageView thumbnail;
        private TextView itemInfo;
    }

listview adapter layout_height

2022-09-22 21:58

1 Answers

It doesn't look like a problem with the code. activity_inspector_list_item.xml from LinearLayout's android:background="@drawable/bg_yellow" I wonder if the bg_yellow used here is a color or an image file. If it's an image, check if the height of the image is large.

And this is another tip. When the UI is not working properly, use the dump view function provided by the Android device monitor. It is helpful when viewing the UI configuration of other apps or analyzing whether the view hierarchy of my app is properly configured.

Android Device Monitor Dump View Hierarchy for UI Automator


2022-09-22 21:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.