android - 用listview滚动的图像

时间:2012-05-15 07:04:49

标签: android listview scrollview

在我的应用程序中,我想显示一个页面顶部有一个图像,下面是名称列表。图像可能占据屏幕的80%,我不想为图像视图或列表视图提供高度。

我试过以下方式,我有两个数组列表。一个数组包含图像的url,另一个文本显示如下

array 1 = ["http://....","A","B","C","D"......]

下一个数组包含0和1,如下所示

array 2 = [0,1,1,1,1.......]

以下是我的列表视图代码

public class listViewHolder 
            {
                ImageView product_hold_image;
                TextView product_hold_subHeading;
            }
            public View getView(final int position, View convertView, ViewGroup parent) 
            {
                listViewHolder holder = null;
                try 
                {
                    if (convertView == null) 
                    {
                        convertView = mLayoutInflater.inflate(R.layout.lst_ly, null);           
                        holder = new listViewHolder();
                        holder.product_hold_image      = (ImageView)convertView.findViewById(R.id.imageView1);
                        holder.product_hold_subHeading = (TextView)convertView.findViewById(R.id.lst_textView1);

                        convertView.setTag(holder);
                    } 
                    else 
                    {
                        holder = (listViewHolder) convertView.getTag();
                    }
                    if(data.get(position).contains("0"))
                    {
                        img = data_phonetxt.get(position).toString();           
                        img = img.replaceAll(" ","%20");        

                        Drawable drawable = LoadImageFromWebOperations(img);
                        holder.product_hold_image.setImageDrawable(drawable);
                    }
                    populateListData(holder, position);
                    notifyDataSetChanged();
                } 
                catch (Exception e) 
                {
                    Log.e("list view holder - error: ",""+e);  
                }
                return convertView;
            }
            public void populateListData(listViewHolder viewHolder, int position) 
            {   
                if(data.get(position).contains("1"))
                {
                    Log.e("data.get(position).contains(0) ","is false");
                    viewHolder.product_hold_image.setVisibility(View.GONE);
                    viewHolder.product_hold_subHeading.setText(data_phonetxt.get(position).toString());
                }
                else if(data.get(position).contains("0"))
                {
                    img = data_phonetxt.get(0).toString();          
                    img = img.replaceAll(" ","%20");        

                    Drawable drawable = LoadImageFromWebOperations(img);
                    viewHolder.product_hold_image.setImageDrawable(drawable);
                }
            }

根据上面的代码我第一次使用顶部的图像和下面的所有文本,但是当我从上到下滚动列表视图时,当我再次移动到顶部时,图像被替换通过一些文字,

有没有其他简单的方法来获得这个,任何建议......

1 个答案:

答案 0 :(得分:0)

我通过在ListActivity中使用单独的视图来获得解决方案。

使用单独的视图作为图像视图,并在listview的标题中添加图像视图

localListView = getListView();
                    LayoutInflater localLayoutInflater = (LayoutInflater)getSystemService("layout_inflater");
                    View localView1 = localLayoutInflater.inflate(R.layout.img1, localListView, false);
                    this.mImageView = ((ImageView)localView1.findViewById(R.id.imageView1));

                    localListView.addHeaderView(localView1, null, false);
                    localListView.setCacheColorHint(0);