我有一个列表视图,显示从互联网上下载,并有如下列表视图中的每一行的自定义版面图:的ListView不显示图像正确
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#00f"
>
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/wish"
android:gravity="center_vertical|center_horizontal"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:text="" />
</LinearLayout>
我getview方法为初级讲座:
public View getView(int arg0, View arg1, ViewGroup arg2)
{
// TODO Auto-generated method stub
View v;
final TextView tv;
if(arg1 == null)
{ // if it's not recycled, initialize some attributes
LayoutInflater lf = (LayoutInflater) conn.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = lf.inflate(R.layout.layitem, arg2, false);
tv = (TextView) v.findViewById(R.id.textView1);
tv.setLayoutParams(new LinearLayout.LayoutParams(width, width/2));
// tv.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);
}
else
{
v = arg1;
tv = (TextView) v.findViewById(R.id.textView1);
}
if(arg0 < count)
{
Bitmap object = getImage(iurl[arg0]);
tv.setBackground(new BitmapDrawable(conn.getResources(), object));
tv.setText(texts[arg0]);
}
else
{
tv.setBackgroundResource(R.drawable.wish);
tv.setText("");
}
return v;
}
我想要做的是我的ListView有20行,我的记录数少于20.so记录填满了行,其余的都有默认背景image.count是实际的记录数。
iurl是包含要从服务器获取的图像名称的数组,而文本是包含消息的数组。
问题是,arg0不超过2,所有行包含索引从0到2的图像,当我向下滚动,它改变图像对应的行号。
我可以在正确的行中放置正确的图像在第一个立场,否则它只会滚动。
我设置了textview的宽度,根据mobile.is的屏幕宽度,它是正确的方式.kindly更新。
没有图像加载的问题。显然,我正在通过asynctask做.images加载正常。 – user2779311