main.xml<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:divider="#00000000"
android:cacheColorHint="#00000000"/></LinearLayout>
list_content.xml<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal" > <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal" > <ImageView
android:id="@+id/image_1"
android:layout_width="80dip"
android:layout_height="110dip"
android:layout_marginTop="15dip" />
</LinearLayout> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal" >
<ImageView
android:id="@+id/image_2"
android:layout_width="80dip"
android:layout_height="110dip"
android:layout_marginTop="15dip" />
</LinearLayout> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal" > <ImageView
android:id="@+id/image_3"
android:layout_width="80dip"
android:layout_height="110dip"
android:layout_marginTop="15dip" />
</LinearLayout>
</LinearLayout>
问题是:上面的布局文件描述的信息是一行显示三列,怎样在自定义的Adapter添加图片,难点是我将URL存放在集合里,在集合里取出来的URL代表的是一个数据,而我要填充一行三列的数据(也就是三个数据),不知道如何按顺序地填充图片,望指教。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:divider="#00000000"
android:cacheColorHint="#00000000"/></LinearLayout>
list_content.xml<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal" > <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal" > <ImageView
android:id="@+id/image_1"
android:layout_width="80dip"
android:layout_height="110dip"
android:layout_marginTop="15dip" />
</LinearLayout> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal" >
<ImageView
android:id="@+id/image_2"
android:layout_width="80dip"
android:layout_height="110dip"
android:layout_marginTop="15dip" />
</LinearLayout> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal" > <ImageView
android:id="@+id/image_3"
android:layout_width="80dip"
android:layout_height="110dip"
android:layout_marginTop="15dip" />
</LinearLayout>
</LinearLayout>
问题是:上面的布局文件描述的信息是一行显示三列,怎样在自定义的Adapter添加图片,难点是我将URL存放在集合里,在集合里取出来的URL代表的是一个数据,而我要填充一行三列的数据(也就是三个数据),不知道如何按顺序地填充图片,望指教。
解决方案 »
- 100分 Android下GPIO模拟串口
- 如何提高adroid软件的兼容性
- 请教,java中点击选项菜单怎么执行active中某button的事件?
- viewgroup如何实现翻页时的3D效果
- Activity后,Activity中的showDialog会报错,求帮忙...
- 求助:能否在应用程序中直接调用系统已经编译好的so库?
- Android传感器API之:磁场Magnetic Field源码与示例
- android自定义控件及特效资料
- java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
- 新手自学安卓到适配器总是遇到空指针异常,求大神指点12
- android做模块化,还不能用插件化,这下悲哀了
- 这样不能访问颜色?
自定义的对象如public class ItemBean
{
private String logoAddress;
public String getLogoAddress()
{
return logoAddress;
} public void setLogoAddress(String logoAddress)
{
this.logoAddress = logoAddress;
}
}
如果我没理解错的话,呵呵
继承BaseAdapter,覆盖getView(int position, View convertView, ViewGroup parent)
我尝试过你所说的方法,运行的结果如下:1 0 0
0 1 0
0 0 1以上是三行三列的,1代表有图片,0代码没有图片。
getView方法是根据position变量来确定多少行,假设我集合中存储了三个数据,那个意味着getView会调用三次,也就是三行,这样就会导致上面的运行结果。
ItemBean item = new ItemBean() // 这里面存储了一个变量,Bitmap picture.生成它的getting和setting方法
ImageView image_01 = (ImageView)findViewById(R.id.xx);
ImageView image_02 = (ImageView)findViewById(R.id.xx);
ImageView image_03 = (ImageView)findViewById(R.id.xx);image_01.setImageBitmap(item.getPicture());// image_02, image_03就不知道怎么为它初始化了。
不要说在item里面加两个变量哦,因为我获到的图片是在同一个服务器地址上,通过服务器的地址用json解析获得所有图片的URL。将URL放进集合中,List<ItemBean> list = new ArrayList<ItemBean>();所以,不能再为ItemBean创建变量了。
可能讲的不是很清楚,望见谅。呵呵!
大概的思路是:
1.从网络上获取到的图片URL存储在集合里
2.继承BaseAdapter,
在重写的getCount方法中写成
return list.size() % 3 == 0 ? list.size() : list.size() + 1
难点是在重写的getView方法中判断,将集合中的数据拆分成每一行三列,如果有第二行的话,再重新迭代getView方法,直到数据完成。哈哈!