android Gallery组件实现的iPhone图片滑动效果实例
2019/7/7 20:14:36
本文主要是介绍android Gallery组件实现的iPhone图片滑动效果实例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
实现的效果图,可左右滑动:
一、先在将Gallery标签放入:
复制代码 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
二、Gallery 需要用Adapter来填充,先从BaseAdapter中派生一个ImageAdapter出来
复制代码 代码如下:
public class ImageAdapter extends BaseAdapter
{
private Context context;
private int[] MyImageIDs =
{ R.drawable.icon, R.drawable.carlogo_52design_09,
R.drawable.carlogo_52design_13, R.drawable.carlogo_52design_19,
R.drawable.carlogo_52design_24, R.drawable.carlogo_52design_27,
R.drawable.carlogo_52design_29, R.drawable.carlogo_52design_31,
R.drawable.carlogo_52design_34, R.drawable.carlogo_52design_36 };
public ImageAdapter(Context context)
{
// TODO Auto-generated constructor stub
this.context = context;
}
@Override
public int getCount()
{
// TODO Auto-generated method stub
return MyImageIDs.length;
}
@Override
public Object getItem(int arg0)
{
// TODO Auto-generated method stub
return arg0;
}
@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 i = new ImageView(this.context);
i.setImageResource(this.MyImageIDs[position]);
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setLayoutParams(new Gallery.LayoutParams(120, 120));
return i;
}
}
{
private Context context;
private int[] MyImageIDs =
{ R.drawable.icon, R.drawable.carlogo_52design_09,
R.drawable.carlogo_52design_13, R.drawable.carlogo_52design_19,
R.drawable.carlogo_52design_24, R.drawable.carlogo_52design_27,
R.drawable.carlogo_52design_29, R.drawable.carlogo_52design_31,
R.drawable.carlogo_52design_34, R.drawable.carlogo_52design_36 };
public ImageAdapter(Context context)
{
// TODO Auto-generated constructor stub
this.context = context;
}
@Override
public int getCount()
{
// TODO Auto-generated method stub
return MyImageIDs.length;
}
@Override
public Object getItem(int arg0)
{
// TODO Auto-generated method stub
return arg0;
}
@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 i = new ImageView(this.context);
i.setImageResource(this.MyImageIDs[position]);
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setLayoutParams(new Gallery.LayoutParams(120, 120));
return i;
}
}
这篇关于android Gallery组件实现的iPhone图片滑动效果实例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-01-18android.permission.read_media_video
- 2024-01-18android_getaddrinfo failed eai_nodata
- 2024-01-18androidmo
- 2024-01-15Android下三种离屏渲染技术
- 2024-01-09Android 蓝牙使用
- 2024-01-06Android对接华为AI - 文本识别
- 2023-11-15代码安全之代码混淆及加固(Android)
- 2023-11-10简述Android语音播报TTS
- 2023-11-06Android WiFi工具类
- 2023-07-22Android开发未来的出路