私はレイアウトでカバーフローを実行しようとしていますが、画像では問題なく完全に機能します。問題はlos*.xmlで実行しようとすることです。
次のエラーがあります。
05-14 09:14:56.901: WARN/ImageView(774): Unable to find resource: 2130903041
05-14 09:14:56.901: WARN/ImageView(774): android.content.res.Resources$NotFoundException: File res/layout/prueba1.xml from drawable resource ID #0x7f030001
05-14 09:14:56.901: WARN/ImageView(774): at android.content.res.Resources.loadDrawable(Resources.java:1697)
05-14 09:14:56.901: WARN/ImageView(774): at android.content.res.Resources.getDrawable(Resources.java:581)
05-14 09:14:56.901: WARN/ImageView(774): at android.widget.ImageView.resolveUri(ImageView.java:489)
05-14 09:14:56.901: WARN/ImageView(774): at android.widget.ImageView.setImageResource(ImageView.java:274)
05-14 09:14:56.901: WARN/ImageView(774): at com.example.coverflow.CoverFlowExample$ImageAdapter.getView(CoverFlowExample.java:77)
05-14 09:14:56.901: WARN/ImageView(774): at android.widget.Gallery.makeAndAddView(Gallery.java:745)
05-14 09:14:56.901: WARN/ImageView(774): at android.widget.Gallery.layout(Gallery.java:622)
05-14 09:14:56.901: WARN/ImageView(774): at android.widget.AbsSpinner.setSelectionInt(AbsSpinner.java:292)
05-14 09:14:56.901: WARN/ImageView(774): at android.widget.AbsSpinner.setSelection(AbsSpinner.java:269)
05-14 09:14:56.901: WARN/ImageView(774): at com.example.coverflow.CoverFlowExample.onCreate(CoverFlowExample.java:30)
05-14 09:14:56.901: WARN/ImageView(774): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-14 09:14:56.901: WARN/ImageView(774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-14 09:14:56.901: WARN/ImageView(774): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-14 09:14:56.901: WARN/ImageView(774): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-14 09:14:56.901: WARN/ImageView(774): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-14 09:14:56.901: WARN/ImageView(774): at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 09:14:56.901: WARN/ImageView(774): at android.os.Looper.loop(Looper.java:123)
05-14 09:14:56.901: WARN/ImageView(774): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-14 09:14:56.901: WARN/ImageView(774): at java.lang.reflect.Method.invokeNative(Native Method)
05-14 09:14:56.901: WARN/ImageView(774): at java.lang.reflect.Method.invoke(Method.java:521)
05-14 09:14:56.901: WARN/ImageView(774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-14 09:14:56.901: WARN/ImageView(774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-14 09:14:56.901: WARN/ImageView(774): at dalvik.system.NativeStart.main(Native Method)
05-14 09:14:56.901: WARN/ImageView(774): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag LinearLayout
05-14 09:14:56.901: WARN/ImageView(774): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:784)
05-14 09:14:56.901: WARN/ImageView(774): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
05-14 09:14:56.901: WARN/ImageView(774): at android.content.res.Resources.loadDrawable(Resources.java:1694)
これはコードです:
package com.example.coverflow;
import java.io.FileInputStream;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
public class CoverFlowExample extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CoverFlow coverFlow;
coverFlow = new CoverFlow(this);
coverFlow.setAdapter(new ImageAdapter(this));
ImageAdapter coverImageAdapter = new ImageAdapter(this);
coverFlow.setAdapter(coverImageAdapter);
coverFlow.setSpacing(-25);
coverFlow.setSelection(0, true);
coverFlow.setAnimationDuration(1000);
setContentView(coverFlow);
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private FileInputStream fis;
// private Integer[] mImageIds = {
//// R.drawable.twitter,
//// R.drawable.centros,
//// R.drawable.seas,
//// R.drawable.estudios,
//// R.drawable.videos
// };
private ImageView[] mImages;
Context context;
LayoutInflater v1 = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View p1 = v1.inflate(R.layout.prueba1, null);
LayoutInflater v2 = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View p2 = v2.inflate(R.layout.prueba2, null);
LayoutInflater v3 = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View p3 = v3.inflate(R.layout.prueba3, null);
public ImageAdapter(Context c) {
mContext = c;
// mImages = new ImageView[mImageIds.length];
}
public int getCount() {
return 1;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
//Use this code if you want to load from resources
ImageView i = new ImageView(mContext);
Bitmap bmp[] = new Bitmap[3];
bmp[0]=p1.getDrawingCache(true);
bmp[1]=p2.getDrawingCache(true);
bmp[2]=p3.getDrawingCache(true);
// i.setImageDrawable(drawable[position]);
i.setLayoutParams(new CoverFlow.LayoutParams(130, 130));
i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
//Make sure we set anti-aliasing otherwise we get jaggies
// BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
// drawable.setAntiAlias(true);
return i;
//return mImages[position];
}
/** 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)));
}
}
}
画像の配列をビューに置き換えるだけで機能するはずですか?ありがとう