Android 加载图片

liujunyu 2011-09-03 05:03:33
我想在屏幕上一次只加载4个图片,依次排列。
我有100个图片,需要分次加载。
点击button "下一页"后,要显示后续的图片。
setImageDrawable(getResources().getDrawable(R.drawable.t4 + 1));//出错
有什么方法吗?
谢谢


下面是layout的配置:

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#f0f8ff"
>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/group_companies"
>

<TableRow>
<ImageButton
android:id="@+id/company1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/t1"
android:background="#f0f8ff"
android:layout_weight="1"
android:layout_marginLeft="0dp"
/>

</TableRow>

<TableRow>
<ImageButton
android:id="@+id/company2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/t2"
android:background="#f0f8ff"
android:layout_weight="1"
android:layout_marginLeft="0dp"
/>

</TableRow>


<TableRow>
<ImageButton
android:id="@+id/company3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/t3"
android:background="#f0f8ff"
android:layout_weight="1"
android:layout_marginLeft="0dp"
/>

</TableRow>

<TableRow>
<ImageButton
android:id="@+id/company4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/t4"
android:background="#f0f8ff"
android:layout_weight="1"
android:layout_marginLeft="0dp"
/>

</TableRow>


<Button android:id="@+id/next"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="100"
android:text="下一页" />

</TableLayout>

</RelativeLayout>
...全文
298 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wenzheng38 2011-09-04
  • 打赏
  • 举报
回复
R.drawable.t4 + 1并不一定是下一个图片的ID号,肯定报ID号找不到错误

用LS的方法,把所有的图片ID号保存在一个数组里,每次读取4个,点击下一页时,读取后面4个图片ID号
franzhong 2011-09-04
  • 打赏
  • 举报
回复
R.drawable.t4 + 1错,会造成找不到图片
可以存个int数组里面包含R.drawable.t4, 5, 6;
依次调用
R.drawable.t4已经被整合为一个int型的了
passself 2011-09-04
  • 打赏
  • 举报
回复
R.drawable.t4 + 1 这样写肯定出错啊,你首先要打印出来这样的id是不是你想要的,不要盲目的去猜,写程序最好的办法就是把需要验证的打印出来,这样你就会明白怎样做了
King_at_csdn 2011-09-03
  • 打赏
  • 举报
回复
把所有id存到一个数组或list里,每次计算下标读4个图片的id分别去setImageDrawable

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧