首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

帮小弟我看看这个代码是什么有关问题啊

2012-05-07 
帮我看看这个代码是什么问题啊?package com.marsimport android.app.Activityimport android.content.Co

帮我看看这个代码是什么问题啊?


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"


android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:spacing="16dp">

</Gallery>
</RelativeLayout>

logcat提示不能启动activity







[解决办法]
错误信息发出来阿亲,光是activity不能启动原因多了去了

热点排行