簡體   English   中英

全屏圖像庫Android

[英]Full screen image gallery Android

對不起我的英語不好。 有一個微型畫廊,當您從圖庫中單擊圖像時,它應該(圖片)以全屏打開。 應用只是通過按圖像而拋出。 我究竟做錯了什么? 主要活動

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

        }
    });
}

}

ImageAdapter

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

公共類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);
}

}

清理您的項目,如果它不起作用

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM