android - 全屏图库安卓

标签 android fullscreen

对不起我的英语。有一个迷你画廊,当您单击画廊中的图像时,它应该(图片)以全屏方式打开。应用程序只需按下图像即可抛出。我究竟做错了什么? 主要 Activity

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
};

全屏图片

public class FullScreenImage extends 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);
}

最佳答案

如果它不起作用,请清理你的项目

 imageView.setLayoutParams( new ViewGroup.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));


change it to

 imageView.setLayoutParams( new LinearLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));

关于android - 全屏图库安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25960180/

相关文章:

android - 无法在主线程中创建处理程序?

Android:当我全屏观看 youtube 视频时,我按下返回键,Activity 完成

java - 如何在框架可见后调用 setUndecorated()?

android - Galaxy S10、S10+ 全屏模式

li 元素中的 div 的 Jquery 单击事件未在移动 Safari 中触发

android - Jackson + SugarOrm id 错误

android - 检查Android MediaPlayer是否已经初始化

java - 找不到方法 AdvertisingIdClient.getAdvertisingIdInfo

android - 如何在android上全屏显示图像

fullscreen - 全屏模式下有多个JavaFX阶段