Gallary装的是缩略图(thumb),ImageSwitcher装的是大图。

不显示图片的一个可能原因是gallery没设置代理器,另一个原因是没使用相对布局。

GalleryActivity.java:

 public class GalleryActivity extends Activity implements OnItemSelectedListener, ViewFactory {
/** Called when the activity is first created. */
private ImageSwitcher is;
private Gallery gallery;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main); is = (ImageSwitcher)findViewById(R.id.imageSwitcher1);
is.setFactory(this);
gallery = (Gallery)findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemSelectedListener(this);
} @Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
is.setImageResource(mImageIds[arg2]); } @Override
public View makeView() {
// TODO Auto-generated method stub
ImageView iv = new ImageView(this);
iv.setBackgroundColor(0xFF000000);
iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
iv.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); return iv;
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub }
class ImageAdapter extends BaseAdapter {
private Context ctx;
public ImageAdapter(Context ctx) {
this.ctx = ctx;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mThumbIds.length-1;
} @Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mThumbIds[position];
} @Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView iv = new ImageView(ctx);
iv.setBackgroundColor(0x000000);
iv.setImageResource(mThumbIds[position]);
iv.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
iv.setBackgroundResource(R.drawable.picture_frame);
return iv;
} }
private int[] mThumbIds = {
R.drawable.sample_thumb_0,
R.drawable.sample_thumb_1,
R.drawable.sample_thumb_2,
R.drawable.sample_thumb_3,
R.drawable.sample_thumb_4,
R.drawable.sample_thumb_5,
R.drawable.sample_thumb_6,
R.drawable.sample_thumb_7,
};
private int[] mImageIds = {
R.drawable.sample_0,
R.drawable.sample_1,
R.drawable.sample_2,
R.drawable.sample_3,
R.drawable.sample_4,
R.drawable.sample_5,
R.drawable.sample_6
}; }

main.xml(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="fill_parent"> <ImageSwitcher
android:id="@+id/imageSwitcher1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" /> <Gallery android:id="@+id/gallery1"
android:background="#55000000"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:spacing="16dp" />
</RelativeLayout>

安卓Gallery配合ImageSwitcher不显示图片的更多相关文章

  1. 用ImageSwitcher实现显示图片(更改图片时有动画效果)

    ImageView和ImageSwitcher都是用来显示图片的.只不过后者在更新显示的图片的时候可以有动画效果. 注意点: 1.ImageSwitcher初始化需要定义一个ViewFactory,该 ...

  2. 解决微信小程序安卓手机访问不到图片,无法显示图片

    关于微信小程序不显示图片 通病可能有以下几个可能性: 非本地图片:确定图片资源存在,copy 图片url再浏览器打开,确定图片资源存在且能正常访问 本地图片:确定相对路径或者绝对路径正确 微信小程序图 ...

  3. ImageSwitcher (图像切换器,显示图片)

    ImageSwitcher继承了ViewSwitcher,主要在切换图片时加入动画效果 使用方法: 1.为ImageSwitcher提供一个ViewFactory,该ViewFactory生成的Vie ...

  4. ImageLoader配合ImageSwitcher的使用

    先在MyApplication中初始化ImageLoader initImageLoader(getApplicationContext()); /** * 初始化ImageLoader * 如果你经 ...

  5. Android训练课程(Android Training) - 高效的显示图片

    高效的显示图片(Displaying BitmapsEfficiently) 了解如何使用通用的技术来处理和读取位图对象,让您的用户界面(UI)组件是可响应的,并避免超过你的应用程序内存限制的方式.如 ...

  6. Android Gallery和ImageSwitcher同步自动(滚动)播放图片库

    本文主要内容是如何让Gallery和ImageSwitcher控件能够同步自动播放图片集 ,看起来较难,然而,实现的方法非常简单, 请跟我慢慢来.总的来说,本文要实现的效果如下图:(截图效果不怎么好) ...

  7. Android中Gallery和ImageSwitcher同步自动(滚动)播放图片库

    本文主要内容是如何让Gallery和ImageSwitcher控件能够同步自动播放图片集 ,看起来较难,然而,实现的方法非常简单, 请跟我慢慢来.总的来说,本文要实现的效果如下图:(截图效果不怎么好) ...

  8. 使用图片视频展示插件blueimp Gallery改造网站的视频图片展示

    在很多情况下,我们网站可能会展示我们的产品图片.以及教程视频等内容,结合一个比较好的图片.视频展示插件,能够使得我们的站点更加方便使用,也更加酷炫,在Github上有很多相关的处理插件可以找来使用,有 ...

  9. 如何使用SOIL在VS2012的 C++环境下显示图片

    先看下效果. 这是一个很无聊的功能....首先说下,我做这个功能的初衷并不是为了实现在控制台中显示图片...(这貌似很无聊) 而是因为自己想做用C做一个游戏:http://q.cnblogs.com/ ...

随机推荐

  1. spline interpolation and draw image by matplotlib

    1 # spline interpolation and draw image by matplotlib from scipy import interpolate import matplotli ...

  2. swift语言点评十-Value and Reference Types

    结论:value是拷贝,Reference是引用 Value and Reference Types Types in Swift fall into one of two categories: f ...

  3. 优动漫PAINT中误删工具怎么办?

    最近收到一些小伙伴的提问,说我不小心把 XXX工具从面板上删掉了怎么办?本教程就来给大家分 享一下遇到这个问题时的三种解决方法,遇到同样问题的小伙伴们赶紧进来看一下哟! 优动漫PAINT下载:http ...

  4. 优动漫PAINT简简单单绘画绣球花

    本文分享使用优动漫PAINT简简单单绘画绣球花教程: 相关资讯还可以关注http://www.dongmansoft.com 最后告诉你绣球花的花语,还是很和谐美好的呢! 绣球花没有茉莉花的芳香四溢, ...

  5. 使用maven插件dockerfile-maven-plugin生成Docker镜像并推送到镜像仓库

    1.引入maven插件 <build> <plugins> <plugin> <groupId>com.spotify</groupId> ...

  6. BZOJ 3881 [Coci2015]Divljak(AC自动机+树状数组)

    建立AC自动机然后,加入一个串之后考虑这个串的贡献.我们把这个串扔到AC自动机里面跑.最后对经过每一个点到的这个点在fail树的根的路径上的点有1的贡献.求链的并,我们把这些点按DFS序排序,然后把每 ...

  7. argparse模块入门介绍——基于python3.7

    转载:https://blog.csdn.net/weixin_41796207/article/details/80846406 首先说明,本人是想要学习如何使用argparse模块,打造命令行程序 ...

  8. 二叉排序树(B-Tree)-c实现

    这个二叉排序树写完了,虽然还有些bug,但还是很高兴的. 主要实现二叉排序树的构建.(*表示稍微重要点) 二叉排序树的打印. 二叉排序树的删除. 代码里的三种情况都测了 顺便附送一个简单的中序遍历,递 ...

  9. Docker学习总结(11)——八个Docker的真实应用场景

    [编者的话]Flux 7介绍了常用的8个Docker的真实使用场景,分别是简化配置.代码流水线管理.提高开发效率.隔离应用.整合服务器.调试能力.多租户环境.快速部署.我们一直在谈Docker,Doc ...

  10. POJ 2607 Fire Station

    Fire Station Time Limit: 5000ms Memory Limit: 65536KB This problem will be judged on PKU. Original I ...