帮小弟我看看这个代码是什么有关问题啊
帮我看看这个代码是什么问题啊?
package com.mars;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher.ViewFactory;
public class MainActivity extends Activity implements OnItemSelectedListener,ViewFactory{
private ImageSwitcher mswitcher;
private Integer[] mImageIds={R.drawable.cc,R.drawable.dd};
private Integer[] mthumbIds={R.drawable.cc,R.drawable.dd};
public class ImageAdapter extends BaseAdapter{
private Context mcontext;
public ImageAdapter(Context c){
mcontext=c;
}
@Override
public int getCount() {
return mthumbIds.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i=new ImageView(mcontext);
i.setImageResource(mthumbIds[position]);
i.setAdjustViewBounds(true);
i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
i.setBackgroundColor(R.drawable.cc);
return i;
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mswitcher=(ImageSwitcher)findViewById(R.id.swithcher);
mswitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));
mswitcher.setFactory(this);
Gallery g=(Gallery)findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
g.setOnItemSelectedListener(this);
}
@Override
public View makeView() {
// TODO Auto-generated method stub
ImageView i=new ImageView(this);
i.setBackgroundColor(0xff000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
//i.setLayoutParams(new );
return i;
}
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
mswitcher.setImageResource(mImageIds[position]);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
布局文件是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageSwitcher
android:id="@+id/swithcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" >
</ImageSwitcher>
<Gallery
android:id="@+id/gallery"
android:background="#55000000"
package com.mars;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher.ViewFactory;
public class MainActivity extends Activity implements OnItemSelectedListener,ViewFactory{
private ImageSwitcher mswitcher;
private Integer[] mImageIds={R.drawable.cc,R.drawable.dd};
private Integer[] mthumbIds={R.drawable.cc,R.drawable.dd};
public class ImageAdapter extends BaseAdapter{
private Context mcontext;
public ImageAdapter(Context c){
mcontext=c;
}
@Override
public int getCount() {
return mthumbIds.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i=new ImageView(mcontext);
i.setImageResource(mthumbIds[position]);
i.setAdjustViewBounds(true);
i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
i.setBackgroundColor(R.drawable.cc);
return i;
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mswitcher=(ImageSwitcher)findViewById(R.id.swithcher);
mswitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));
mswitcher.setFactory(this);
Gallery g=(Gallery)findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
g.setOnItemSelectedListener(this);
}
@Override
public View makeView() {
// TODO Auto-generated method stub
ImageView i=new ImageView(this);
i.setBackgroundColor(0xff000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
//i.setLayoutParams(new );
return i;
}
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
mswitcher.setImageResource(mImageIds[position]);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
布局文件是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageSwitcher
android:id="@+id/swithcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" >
</ImageSwitcher>
<Gallery
android:id="@+id/gallery"
android:background="#55000000"