Android 带有自定义适配器的Coverflow
我想用自定义适配器创建一个封面流程(图像视图为缩略图,文本视图为标题,进度条指示某些进度…) CoverFlow小部件的所有示例或实现都基于Gallery(witch仅支持图像集合) 有什么可以帮助我的提示和想法吗Android 带有自定义适配器的Coverflow,android,coverflow,Android,Coverflow,我想用自定义适配器创建一个封面流程(图像视图为缩略图,文本视图为标题,进度条指示某些进度…) CoverFlow小部件的所有示例或实现都基于Gallery(witch仅支持图像集合) 有什么可以帮助我的提示和想法吗 谢谢:)您可以使用惰性适配器来实现这一点。您必须在图像加载器类的解码文件中创建反射图像。接下来,必须从自定义适配器类的getview方法返回图像视图 以下是示例代码: In main activity: CoverFlow coverflow=(CoverFlow)findView
谢谢:)您可以使用惰性适配器来实现这一点。您必须在图像加载器类的解码文件中创建反射图像。接下来,必须从自定义适配器类的getview方法返回图像视图 以下是示例代码:
In main activity:
CoverFlow coverflow=(CoverFlow)findViewById(R.id.yourcoverflowid);
coverflow.setAdapter(new customadapter(getActivity(),list,imagesize));
In getview method of custom adapter:
ImageView i=new ImageView(activity);
imageLoader.DisplayImage(data.get(position).getimage(),i);
i.setPadding(0,5,0,0);
i.setLayoutParams(new CoverFlow.LayoutParams(width,height));
i.setScaleType(ImageView.ScaleType.MATRIX);
return i;
In decodefile method of imageloader class
试一试{
最终反射率ap=4
Bitmap originalImage;
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
FileInputStream stream1=new FileInputStream(f);
originalImage=BitmapFactory.decodeStream(stream1);
stream1.close();
int width = originalImage.getWidth();
int height = originalImage.getHeight();
//This will not scale but will flip on the Y axis
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
//Create a Bitmap with the flip matrix applied to it.
//We only want the bottom half of the image
Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height/2, width, height/2, matrix, false);
//Create a new bitmap with same width but taller to fit reflection
Bitmap bitmapWithReflection = Bitmap.createBitmap(width
, (height + height/2), Config.ARGB_8888);
//Create a new Canvas with the bitmap that's big enough for
//the image plus gap plus reflection
Canvas canvas = new Canvas(bitmapWithReflection);
//Draw in the original image
canvas.drawBitmap(originalImage, 0, 0, null);
//Draw in the gap
Paint deafaultPaint = new Paint();
canvas.drawRect(0, height, width, height + reflectionGap, deafaultPaint);
//Draw in the reflection
canvas.drawBitmap(reflectionImage,0, height + reflectionGap, null);
//Create a shader that is a linear gradient that covers the reflection
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0,
bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff,
TileMode.CLAMP);
//Set the paint to use this shader (linear gradient)
paint.setShader(shader);
//Set the Transfer mode to be porter duff and destination in
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
//Draw a rectangle using the paint with our linear gradient
canvas.drawRect(0, height, width,
bitmapWithReflection.getHeight() + reflectionGap, paint);
return bitmapWithReflection;
如果您希望所有视图的coverflow都能从蜂巢中获得,您可以在蜂巢中使用方法View.setRotationY(rotationangle)旋转视图。我使用的解决方法可能不是您所需要的。不过,这是我能想到的。。。 我将所需内容放入
线性布局
,然后将其转换为位图
:
LayoutInflater inflater = (LayoutInflater) ClassifiedActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.my_layout_as_imageview,
null);
layout.setBackgroundResource(R.drawable.stub);
layout.setDrawingCacheEnabled(true);
layout.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());
layout.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(layout.getDrawingCache());
layout.setDrawingCacheEnabled(false); // clear drawing cache
ImageView iv= (ImageView) findViewById(R.id.imageView1);
iv.setImageBitmap(b);
我的布局XML如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Medium Text" />
</LinearLayout>
帮助我将
线性布局
转换为位图
这相当容易;您使用与listview相同的适配器。扩展基本适配器
,使用视图保持架
模式,并在
public View getView(int position, View convertView, ViewGroup parent) {
方法。但您应该更改
transformImageBitmap(THIS child, Transformation t, int rotationAngle)
到
在
CoverFlow.java
中,或者你会得到ClassCastExceptions
这不是我的观点!!我在android上尝试了许多CoverFlow实现,它们大多是Gallery的实现(不推荐使用…),但几乎所有的都只是显示“图像”。我想创建自定义封面:图像、测试、按钮等。您找到解决方案了吗?我尝试将ImageView更改为LinearLayout,但没有成功,目前我正在尝试自定义ImageView。到目前为止,效果不太好。:(不,我仍然坚持下去,我没有找到解决方案……如果你找到了更好的方法,那么可以通过回答或评论自由分享。)
transformImageBitmap(View child, Transformation t, int rotationAngle)