ListView控件是显示在列表中的项目的Andr​​oid目瞪口呆 [英] ListView is showing gapes in list items Android

查看:171
本文介绍了ListView控件是显示在列表中的项目的Andr​​oid目瞪口呆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过setListAdapter,高效的适配器来实现的ListView。我想,当列表显示那么背景不应该被重复。我的code是重复list.xml的整个布局,由于它我的名单项与这么多的差距呈现。

i am trying to implement listView through setListAdapter and Efficient Adapter. I want that when list is show then the background should not be repeat. My code is repeating the whole layout of list.xml due to which my list item are showing with so much gap.

现在我的名单正在这样的:

但是我想这种类型的视图:

这里是我的editText.xml我在其中键入单词和列表视图中打开。

<EditText
    android:id="@+id/start_edit"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_gravity="top|left"
    android:ems="10"
    android:hint="Type to search"
    android:paddingLeft="50dp" >

    <requestFocus />
</EditText>

这个布局是list.xml:

<RelativeLayout
    android:id="@+id/RelativeLayout_list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/blue_cellbar" >  

在list.xml文件在Effecient适配器重复布局:

the list.xml file is repeating the layout in Effecient adapter:

这里是我的code:

listAdapter = new EfficientAdapter2(this);
    setListAdapter(listAdapter);



public static class viewHolder2 {
    TextView word;
    TextView meaning;
    ImageView image;
    ImageView image_color;
    RelativeLayout cell;

}



private class EfficientAdapter2 extends BaseAdapter implements Filterable,OnItemClickListener {

    private Context context;
    LayoutInflater inflater;

    public EfficientAdapter2(Context context) {

        this.context = context;
        inflater = LayoutInflater.from(context);

    }

    public int getCount() {


        //  if(SearchWordString.isEmpty()==false)
        //  {

        return SearchWordString.size();
        /// }

        //return 0;
    }

    public Object getItem(int position) {

        return position;
    }

    public long getItemId(int position) {

        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder2 holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.list, null);

            ViewToUse=parent;
            holder = new viewHolder2();
            //  Log.i("View","is Null");
            convertView.setTag(holder);

        } else {

            //Log.i("View","is not Null");
            holder = (viewHolder2) convertView.getTag();
        }


        holder.cell = (RelativeLayout) convertView
                .findViewById(R.id.RelativeLayout_list);

        return convertView;
    }

更新

public class Start extends ListActivity implements OnTouchListener,

android.view.GestureDetector.OnGestureListener {

android.view.GestureDetector.OnGestureListener {

// ///////////////////////////////////////////// ///////
    / * 的**的 * 的* 的内部类VIEWHOLDER * 的**的 * **** /
    // //////////////////////////////////////////////// ////
的onCreate()
{
ListView控件list_to_use = getListView();
listAdapter =新EfficientAdapter2(本);
        list_to_use.setAdapter(listAdapter);
        list_to_use.setBackgroundColor(2);
        viewFlipper =(ViewFlipper)findViewById(R.id.viewFlipper1);

// //////////////////////////////////////////////////// /***** INNER CLASS VIEWHOLDER ********/ // //////////////////////////////////////////////////// onCreate() { ListView list_to_use = getListView(); listAdapter = new EfficientAdapter2(this); list_to_use.setAdapter(listAdapter); list_to_use.setBackgroundColor(2); viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper1);

    search = (EditText) findViewById(R.id.start_edit);

    search.addTextChangedListener(myTextWatcher);

}
    公共静态类viewHolder2 {
        TextView的话。
        TextView的意思;
        ImageView的形象;
        ImageView的image_color;
        RelativeLayout的细胞;

} public static class viewHolder2 { TextView word; TextView meaning; ImageView image; ImageView image_color; RelativeLayout cell;

}

// ////////////////////////////////////////////////////
/*********** INNER CLASS EfficientAdapter ************/
// ////////////////////////////////////////////////////

private class EfficientAdapter2 extends BaseAdapter implements Filterable,OnItemClickListener {

    private Context context;
    LayoutInflater inflater;

    public EfficientAdapter2(Context context) {

        this.context = context;
        inflater = LayoutInflater.from(context);

    }

    public int getCount() {


        //  if(SearchWordString.isEmpty()==false)
        //  {

        return SearchWordString.size();
        /// }

        //return 0;
    }

    public Object getItem(int position) {

        return position;
    }

    public long getItemId(int position) {

        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder2 holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.list_search_item, null);

            ViewToUse=parent;
            holder = new viewHolder2();
            //  Log.i("View","is Null");
            convertView.setTag(holder);

            holder.word = (TextView) convertView.findViewById(R.id.title_list);
            holder.meaning = (TextView) convertView
                    .findViewById(R.id.textView_meaning_list);
            holder.image = (ImageView) convertView
                    .findViewById(R.id.image_list);
            holder.image_color = (ImageView) convertView
                    .findViewById(R.id.imageView_color_list);
            holder.cell = (RelativeLayout) convertView
                    .findViewById(R.id.RelativeLayout_list);

        } else {

            //Log.i("View","is not Null");

            holder = (viewHolder2) convertView.getTag();
        }

}
}

} }

main.xml中:

<?xml version="1.0" encoding="utf-8"?>

<EditText
    android:id="@+id/start_edit"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_gravity="top|left"
    android:ems="10"
    android:hint="Type to search"
    android:paddingLeft="50dp" >

    <requestFocus />
</EditText>

<ViewFlipper
    android:id="@+id/viewFlipper1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="top|left"
    android:layout_marginTop="50dp" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/blue_home"
            android:fastScrollEnabled="true"
            android:smoothScrollbar="true"
            android:divider="@drawable/blue_dic"
            android:dividerHeight="250sp" >

        </ListView>

    </FrameLayout>

</ViewFlipper>

有关的ListView行:

rows for listView:

<?xml version="1.0" encoding="utf-8"?>

<ImageView
    android:id="@+id/image_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/abacus_thumbnail"
    android:scaleType="centerCrop" />

<ImageView
    android:id="@+id/imageView_color_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/blue_thumbnail" />

<TextView
    android:id="@+id/title_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/image_list"
    android:layout_marginLeft="20dp"
    android:layout_toRightOf="@+id/image_list"
    android:gravity="center"
    android:text="Abacus"
    android:textColor="#000000"
    android:textSize="30sp"
    android:textStyle="bold"
    android:typeface="sans" />

<TextView
    android:id="@+id/textView_meaning_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/title_list"
    android:layout_below="@+id/title_list"
    android:layout_marginTop="10dp"
    android:text="TextView"
    android:textColor="#000000"
    android:textSize="25sp" />

推荐答案

我希望你没有提供的android:在你的布局文件dividerHeight 属性下&LT;的ListView /&GT;
如果是这样,请删除它。

I hope you have not provide android:dividerHeight attribute in your layout file under <ListView/> If so please remove it.

这篇关于ListView控件是显示在列表中的项目的Andr​​oid目瞪口呆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆