【发布时间】:2014-09-21 14:23:19
【问题描述】:
对不起我的英语。有一个迷你画廊,当您单击画廊中的图像时,它应该(图片)以全屏方式打开。应用程序只需按图像即可。我究竟做错了什么? 主活动
public class MainAcTwo extends Activity {
@SuppressWarnings("deprecation")
Gallery gallery;
ImageView bigimage;
@SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.two);
gallery=(Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
long imageId = ImageAdapter.ThumbsIds[position];
Intent fullScreenIntent = new Intent(v.getContext(), FullScreenImage.class);
fullScreenIntent.putExtra(MainAcTwo.class.getName(), imageId);
MainAcTwo.this.startActivity(fullScreenIntent);
}
});
}
}
图像适配器
public class ImageAdapter extends BaseAdapter implements SpinnerAdapter {
private Context context;
public ImageAdapter(Context context) {
// TODO Auto-generated constructor stub
this.context = context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return ThumbsIds.length;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup arg2) {
// TODO Auto-generated method stub
ImageView imageView=null;
if(convertView == null) {
imageView = new ImageView(context);
imageView.setLayoutParams(new Gallery.LayoutParams(215, 200));
imageView.setPadding(8, 8, 8, 8);
}else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(ThumbsIds[position]);
return imageView;
}
public static Integer[] ThumbsIds={
R.drawable.abs_icla,
R.drawable.abs_dog,
R.drawable.abs_flow,
R.drawable.abs_neb,
R.drawable.abs_rad
};
}
全屏图像
公共类 FullScreenImage 扩展 Activity {
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.full_image);
Intent intent = getIntent();
long imageId = (Long) intent.getExtras().get(FullScreenImage.class.getName());
ImageView imageView = (ImageView) findViewById(R.id.fullImage);
imageView.setLayoutParams( new ViewGroup.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
imageView.setImageResource((int) imageId);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
}
}
【问题讨论】:
-
它抛出的错误是什么,在哪一行?
-
当我点击图片时,在 logCat 中写道:“不幸的是,myProgect 已停止”: FATAL EXCEPTION: main java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget .LinearLayout$LayoutParams atandroid.widget.LinearLayout.measureVertical(LinearLayout.java:655) at android.widget.LinearLayout.onMeasure(LinearLayout.java:574) at android.view.View.measure at android.view.ViewGroup.measureChildWithMargins( ViewGroup.java:4814) 在 android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 在 android.view.View.measure(View.java:15172) ________________
-
尝试清理项目和建筑。也许在 xml 文件中有些混乱,因为我没有看到任何线性布局,只有一个 ImageView
标签: android fullscreen