我想創建一個自定義適配器的Cover Flow(圖片查看縮略圖,文本查看標題,進度條表示了一定的進展..)。的CoverFlow與自定義適配器
所有的例子或蓋流小部件的實現是基於廊(巫支持圖像的集合,僅)。
是否有任何提示,想法,可以幫助我嗎?
謝謝:)
我想創建一個自定義適配器的Cover Flow(圖片查看縮略圖,文本查看標題,進度條表示了一定的進展..)。的CoverFlow與自定義適配器
所有的例子或蓋流小部件的實現是基於廊(巫支持圖像的集合,僅)。
是否有任何提示,想法,可以幫助我嗎?
謝謝:)
您可以通過使用惰性適配器來實現。您必須在Image loader類的解碼文件中創建反射圖像。接下來,您必須從自定義適配器類的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
嘗試{ 最終詮釋reflectionGap = 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;
這不是我的觀點!我嘗試在Android上很多的CoverFlow實現,但它們大多是畫廊的實現(它被廢棄了.. )。但是幾乎所有的人都只是簡單地顯示「圖片」,我想創建一個自定義封面:圖片,測試,按鈕,... –
。
我使用可能不是你所需要的解決方法。然而,這是我能想出... 我把任何我想要的LinearLayout
,然後將其轉換爲Bitmap
:
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>
This answer幫助我將LinearLayout
轉換爲Bitmap
。
如果你找到一個更好的方法來做到這一點,然後可以自由分享答案或評論:) – Sufian
這很容易做到;您使用與例如列表視圖相同的適配器。擴展BaseAdapter
,使用ViewHolder
模式,並在
public View getView(int position, View convertView, ViewGroup parent) {
方法返回的膨脹視圖。但是,你應該改變
transformImageBitmap(THIS child, Transformation t, int rotationAngle)
到
transformImageBitmap(View child, Transformation t, int rotationAngle)
在CoverFlow.java
否則你會得到ClassCastExceptions
。
你可以向我們展示ImageAdapter代碼嗎? – himanshu
您是否能夠找到解決方案?我嘗試將ImageView更改爲LinearLayout,但它不起作用,目前我正在嘗試自定義ImageView。目前爲止看起來不太好。 :( – Sufian
沒有我仍然停留在上面,我沒有找到一個解決方案... –