我正在开发一个应用程序,因为我已经使用coverflow动画显示我的自定义设计,当我只放置图像时它的样本工作正常...但我尝试使用我的自定义设计xml我失败了......
改变了
transformImageBitmap(THIS child,Transformation t,int rotationAngle) 到
transformImageBitmap(View child,Transformation t,int rotationAngle)
在CoverFlow.java中但我得到的是ClassCastExceptions。
重复问题 Coverflow with custom adapter
我需要的输出 我来到这里
public class CoverFlowExample extends Activity {
ImageAdapter coverImageAdapter;
/** Called when the activity is first created. */
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Use this if you want to use XML layout file
setContentView(R.layout.main);
LinearLayout llMain = (LinearLayout) findViewById(R.id.llLayout);
LinearLayout.LayoutParams layoutParams;
CoverFlow coverFlow;
coverFlow = new CoverFlow(this);
coverFlow.setAdapter(new ImageAdapter(this));
coverImageAdapter = new ImageAdapter(this);
coverFlow.setAdapter(coverImageAdapter);
coverFlow.setSpacing(-50);
coverFlow.setSelection(8, true);
layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, 20, 0, 0);
coverFlow.setLayoutParams(layoutParams);
llMain.addView(coverFlow);
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private FileInputStream fis;
private Integer[] mImageIds = { R.drawable.kasabian_kasabian, R.drawable.starssailor_silence_is_easy,
R.drawable.killers_day_and_age, R.drawable.garbage_bleed_like_me,
R.drawable.death_cub_for_cutie_the_photo_album, R.drawable.kasabian_kasabian,
R.drawable.massive_attack_collected, R.drawable.muse_the_resistance,
R.drawable.starssailor_silence_is_easy };
private ImageView[] mImages;
public ImageAdapter(Context c) {
mContext = c;
mImages = new ImageView[mImageIds.length];
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
convertView = inflater.inflate(R.layout.sample_item, parent, false);
LinearLayout llSub = (LinearLayout)convertView.findViewById(R.id.llSub);
ImageView imageView = (ImageView)convertView.findViewById(R.id.imgDisplay);
imageView.setImageResource(mImageIds[position]);
imageView.setLayoutParams(new CoverFlow.LayoutParams(260, 130));
imageView.setScaleType(ImageView.ScaleType.MATRIX);
return imageView;
**Problem facing here**
//Fail if i retrun my view
//return convertView;
}
/**
* Returns the size (0.0f to 1.0f) of the views depending on the
* 'offset' to the center.
*/
public float getScale(boolean focused, int offset) {
/* Formula: 1 / (2 ^ offset) */
return Math.max(0, 1.0f / (float) Math.pow(2, Math.abs(offset)));
}
}
}
如果我返回自定义设计视图,我在getview中会遇到异常
sample_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/llSub"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical"
android:padding="5dip" >
<ImageView
android:id="@+id/imgDisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/death_cub_for_cutie_the_photo_album" />
</LinearLayout>
</LinearLayout>
我的日志
06-03 16:34:17.196: E/AndroidRuntime(23511): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.coverflow/com.example.coverflow.CoverFlowExample}: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.ImageView
06-03 16:34:17.196: E/AndroidRuntime(23511): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
06-03 16:34:17.196: E/AndroidRuntime(23511): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2095)
06-03 16:34:17.196: E/AndroidRuntime(23511): at android.app.ActivityThread.access$600(ActivityThread.java:137)
06-03 16:34:17.196: E/AndroidRuntime(23511): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
06-03 16:34:17.196: E/AndroidRuntime(23511): at android.os.Handler.dispatchMessage(Handler.java:99)
06-03 16:34:17.196: E/AndroidRuntime(23511): at android.os.Looper.loop(Looper.java:213)
06-03 16:34:17.196: E/AndroidRuntime(23511): at android.app.ActivityThread.main(ActivityThread.java:4793)
06-03 16:34:17.196: E/AndroidRuntime(23511): at java.lang.reflect.Method.invokeNative(Native Method)
06-03 16:34:17.196: E/AndroidRuntime(23511): at java.lang.reflect.Method.invoke(Method.java:511)
06-03 16:34:17.196: E/AndroidRuntime(23511): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-03 16:34:17.196: E/AndroidRuntime(23511): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
06-03 16:34:17.196: E/AndroidRuntime(23511): at dalvik.system.NativeStart.main(Native Method)
06-03 16:34:17.196: E/AndroidRuntime(23511): Caused by: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.ImageView
06-03 16:34:17.196: E/AndroidRuntime(23511): at com.example.coverflow.CoverFlow.makeAndAddView(CoverFlow.java:854)
06-03 16:34:17.196: E/AndroidRuntime(23511): at com.example.coverflow.CoverFlow.layout(CoverFlow.java:670)
06-03 16:34:17.196: E/AndroidRuntime(23511): at com.example.coverflow.CoverAbsSpinner.setSelectionInt(CoverAbsSpinner.java:315)
06-03 16:34:17.196: E/AndroidRuntime(23511): at com.example.coverflow.CoverAbsSpinner.setSelection(CoverAbsSpinner.java:291)
06-03 16:34:17.196: E/AndroidRuntime(23511): at com.example.coverflow.CoverFlowExample.onCreate(CoverFlowExample.java:51)
06-03 16:34:17.196: E/AndroidRuntime(23511): at android.app.Activity.performCreate(Activity.java:5008)
06-03 16:34:17.196: E/AndroidRuntime(23511): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
06-03 16:34:17.196: E/AndroidRuntime(23511): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034)
任何人都可以帮助我
感谢Adavance