Android中列表项之间缺少分隔符

Android中列表项之间缺少分隔符,android,android-layout,Android,Android Layout,我使用了一个自定义数组适配器来填充我的列表视图。我面临的问题是第四个和第五个列表项之间缺少分隔符 代码如下: public class Clubs extends ListActivity{ private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; private Bitmap mIcon1; private

我使用了一个自定义数组适配器来填充我的列表视图。我面临的问题是第四个和第五个列表项之间缺少分隔符

代码如下:

public class Clubs extends ListActivity{

    private static class EfficientAdapter extends BaseAdapter {
        private LayoutInflater mInflater;
        private Bitmap mIcon1;
        private Bitmap mIcon2;

        public EfficientAdapter(Context context) {
            // Cache the LayoutInflate to avoid asking for a new one each time.
            mInflater = LayoutInflater.from(context);

            // Icons bound to the rows.
            mIcon1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.yellow_offline);
            mIcon2 = BitmapFactory.decodeResource(context.getResources(), R.drawable.green_online);
        }

        /**
         * The number of items in the list is determined by the number of speeches
         * in our array.
         *
         * @see android.widget.ListAdapter#getCount()
         */
        public int getCount() {
            return DATA.length;
        }

        /**
         * Since the data comes from an array, just returning the index is
         * sufficent to get at the data. If we were using a more complex data
         * structure, we would return whatever object represents one row in the
         * list.
         *
         * @see android.widget.ListAdapter#getItem(int)
         */
        public Object getItem(int position) {
            return position;
        }

        /**
         * Use the array index as a unique id.
         *
         * @see android.widget.ListAdapter#getItemId(int)
         */
        public long getItemId(int position) {
            return position;
        }

        /**
         * Make a view to hold each row.
         *
         * @see android.widget.ListAdapter#getView(int, android.view.View,
         *      android.view.ViewGroup)
         */
        public View getView(int position, View convertView, ViewGroup parent) {
            // A ViewHolder keeps references to children views to avoid unneccessary calls
            // to findViewById() on each row.
            ViewHolder holder;

            // When convertView is not null, we can reuse it directly, there is no need
            // to reinflate it. We only inflate a new View when the convertView supplied
            // by ListView is null.
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.people_list_item, null);

                // Creates a ViewHolder and store references to the two children views
                // we want to bind data to.
                holder = new ViewHolder();
                holder.text = (TextView) convertView.findViewById(R.id.textpeople);
                holder.icon = (ImageView) convertView.findViewById(R.id.image);

                convertView.setTag(holder);
            } else {
                // Get the ViewHolder back to get fast access to the TextView
                // and the ImageView.
                holder = (ViewHolder) convertView.getTag();
            }

            // Bind the data efficiently with the holder.
            holder.text.setText(DATA[position]);
            holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);

            return convertView;
        }

        static class ViewHolder {
            TextView text;
            ImageView icon;
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(new EfficientAdapter(this));
    }

    private static final String[] DATA = {
            "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam",
            "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis",
            };
}
以下是xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget31"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
>

<LinearLayout
android:id="@+id/widget321"
android:layout_width="479dip"
android:layout_height="54dip"
android:layout_marginTop="16dip"
>

<ImageView
android:id="@+id/image"
android:layout_width="24dip"
android:layout_height="24dip"
android:layout_marginLeft="14dip"
android:layout_marginTop="5dip"
android:src="@drawable/green_online">
</ImageView>

<TextView
android:id="@+id/textpeople"
android:layout_marginLeft="10dip"
android:textColor="#FFF5EE" 
android:layout_height="29dip" 
android:textSize="16sp" 
android:layout_width="400dip" 
android:layout_marginTop="7dip"
>
</TextView>
</LinearLayout>
</LinearLayout>

简单的方法是在
onCreate
方法中调用
setDividerHeight(2)
。更复杂的是,你需要确保你的资源正确地放在布局hdpi/layout中,因为那里发生的事情是操作系统接近1dpi到0dpi,因为应用程序在兼容模式下运行。还要检查清单中的
支持屏幕
属性(尝试将所有内容设置为true)

简单的方法是在
onCreate
方法中调用
setDividerHeight(2)
。更复杂的是,你需要确保你的资源正确地放在布局hdpi/layout中,因为那里发生的事情是操作系统接近1dpi到0dpi,因为应用程序在兼容模式下运行。还要检查清单中的
支持屏幕
属性(尝试将所有内容设置为true)

您正在测试的设备我在HTC tatoo中遇到了类似的问题,并发现其唯一的设备特定性我正在emulator中进行测试。您正在测试的设备我在HTC tatoo中遇到了类似的问题,并发现其唯一的设备特定性我正在emulator中进行测试。您能告诉我将setDividerHeight()准确放置在何处吗在完整语法中。我尝试将其放入oncreate中。这会引发编译错误。您也可以在xml中尝试:android:dividerHeight=“3dip”您能告诉我在完整语法中setDividerHeight()的确切位置吗。我尝试将其放入oncreate中。这会引发编译错误。您也可以在xml中尝试:android:dividerHeight=“3dip”
ListView lv=getListView();
 lv.setDividerHeight(2);