package com.lee.gallery3d;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.Toast;
import com.lee.gallery3d.utils.BitmapUtil;
import com.lee.gallery3d.widget.GalleryFlow;
public class GalleryFlowActivity extends Activity
{
GalleryFlow mGallery = null;
ArrayList<BitmapDrawable> mBitmaps = new ArrayList<BitmapDrawable>();
View.OnClickListener mListener = new View.OnClickListener()
{
@Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.space_confirm_btn:
onSpaceBtnClick(v);
break;
case R.id.max_zoom_confirm_btn:
onMaxZoomBtnClick(v);
break;
case R.id.max_rotate_angle_confirm_btn:
onMaxAngleBtnClick(v);
break;
}
}
};
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
generateBitmaps();
mGallery = (GalleryFlow) findViewById(R.id.gallery_flow);
mGallery.setBackgroundColor(Color.GRAY);
mGallery.setSpacing(50);
mGallery.setFadingEdgeLength(0);
mGallery.setGravity(Gravity.CENTER_VERTICAL);
mGallery.setAdapter(new GalleryAdapter());
findViewById(R.id.space_confirm_btn).setOnClickListener(mListener);
findViewById(R.id.max_zoom_confirm_btn).setOnClickListener(mListener);
findViewById(R.id.max_rotate_angle_confirm_btn).setOnClickListener(mListener);
}
private void onSpaceBtnClick(View v)
{
EditText editText = (EditText) findViewById(R.id.space_edittext);
String text = editText.getText().toString();
try
{
int spacing = Integer.parseInt(text);
if (spacing >= -60 && spacing <= 60)
{
mGallery.setSpacing(spacing);
((GalleryAdapter)mGallery.getAdapter()).notifyDataSetChanged();
}
else
{
Toast.makeText(this,
getResources().getString(R.string.gallery_space_text_hint),
Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private void onMaxZoomBtnClick(View v)
{
EditText editText = (EditText) findViewById(R.id.max_zoom_edittext);
String text = editText.getText().toString();
try
{
int maxZoom = Integer.parseInt(text);
if (maxZoom >= -120 && maxZoom <= 120)
{
mGallery.setMaxZoom(maxZoom);
((GalleryAdapter)mGallery.getAdapter()).notifyDataSetChanged();
}
else
{
Toast.makeText(this,
getResources().getString(R.string.gallery_max_zoom_text_hint),
Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private void onMaxAngleBtnClick(View v)
{
EditText editText = (EditText) findViewById(R.id.max_rotate_angle_edittext);
String text = editText.getText().toString();
try
{
int maxRotationAngle = Integer.parseInt(text);
if (maxRotationAngle >= -60 && maxRotationAngle <= 60)
{
mGallery.setMaxRotationAngle(maxRotationAngle);
((GalleryAdapter)mGallery.getAdapter()).notifyDataSetChanged();
}
else
{
Toast.makeText(this,
getResources().getString(R.string.gallery_max_rotate_angle_text_hint),
Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private void generateBitmaps() {
int[] ids ={
R.drawable.a,
R.drawable.b,
R.drawable.c,
R.drawable.d,
R.drawable.e,
R.drawable.f,
R.drawable.g,
R.drawable.h,
R.drawable.i,
R.drawable.j,
R.drawable.k,
R.drawable.l,
R.drawable.aa,
R.drawable.bb,
R.drawable.cc
};
for (int id : ids) {
Bitmap bitmap = createReflectedBitmapById(id);
if (null != bitmap)
{
BitmapDrawable drawable = new BitmapDrawable(bitmap);
drawable.setAntiAlias(true);
mBitmaps.add(drawable);
}
}
}
private Bitmap createReflectedBitmapById(int resId) {
Drawable drawable = getResources().getDrawable(resId);
if (drawable instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
Bitmap reflectedBitmap = BitmapUtil.createReflectedBitmap(bitmap);
return reflectedBitmap;
}
return null;
}
private class GalleryAdapter extends BaseAdapter {
@Override
public int getCount() {
return mBitmaps.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (null == convertView){
convertView = new MyImageView(GalleryFlowActivity.this);
convertView.setLayoutParams(new Gallery.LayoutParams(110, 184));
}
ImageView imageView = (ImageView)convertView;
imageView.setImageDrawable(mBitmaps.get(position));
imageView.setScaleType(ScaleType.FIT_XY);
return imageView;
}
}
private class MyImageView extends ImageView {
public MyImageView(Context context) {
this(context, null);
}
public MyImageView(Context context, AttributeSet attrs) {
super(context, attrs, 0);
}
public MyImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Gallery 投影+3D
共66个文件
png:30个
class:13个
java:5个
需积分: 3 8 下载量 104 浏览量
2013-07-10
17:42:42
上传
评论
收藏 2.7MB ZIP 举报
温馨提示
这个demo实现了类似iOS上面的CoverFlow功能。 主要有两个功能 1, 实现图片的倒影效果 2,重写gallery的一些方法实现Y轴上的旋转,Z轴上的缩放。
资源推荐
资源详情
资源评论
收起资源包目录
Gallery投影+3D.zip (66个子文件)
GalleryͶӰ+3D
GalleryFlow
AndroidManifest.xml 783B
res
layout
main.xml 4KB
drawable-ldpi
ic_launcher.png 2KB
drawable
f.png 48KB
i.png 51KB
c.png 49KB
g.png 38KB
cc.jpg 69KB
h.png 46KB
j.png 44KB
e.png 51KB
a.png 37KB
bb.jpg 114KB
k.png 29KB
b.png 45KB
d.png 44KB
aa.jpg 96KB
l.png 47KB
drawable-mdpi
ic_launcher.png 3KB
drawable-hdpi
ic_launcher.png 4KB
drawable-xhdpi
values
strings.xml 875B
proguard.cfg 1KB
src
com
lee
gallery3d
widget
GalleryFlow.java 5KB
GalleryFlowActivity.java 7KB
utils
BitmapUtil.java 5KB
bin
classes
com
lee
gallery3d
GalleryFlowActivity$1.class 1KB
widget
GalleryFlow.class 4KB
BuildConfig.class 343B
GalleryFlowActivity$MyImageView.class 1KB
R.class 524B
GalleryFlowActivity$GalleryAdapter.class 2KB
R$layout.class 391B
R$attr.class 337B
utils
BitmapUtil.class 4KB
R$id.class 652B
R$string.class 784B
GalleryFlowActivity.class 5KB
R$drawable.class 782B
dexedLibs
annotations-07ebad7cbc3fcee3bb91268d68495984.jar 943B
AndroidManifest.xml 783B
res
drawable-ldpi
ic_launcher.png 2KB
drawable
f.png 37KB
i.png 38KB
c.png 39KB
g.png 41KB
h.png 31KB
j.png 38KB
e.png 38KB
a.png 35KB
k.png 25KB
b.png 41KB
d.png 36KB
l.png 37KB
drawable-mdpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
jarlist.cache 119B
classes.dex 17KB
resources.ap_ 731KB
GalleryFlow.apk 740KB
.classpath 364B
assets
project.properties 361B
default.properties 361B
.settings
org.eclipse.core.resources.prefs 57B
.project 847B
gen
com
lee
gallery3d
R.java 2KB
BuildConfig.java 159B
共 66 条
- 1
资源评论
LT_F
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功