assetsから呼び出した画像をgridviewで表示して、サムネイルをタップした際に画面全体に表示させたいのですが、やり方がわかりません。
画像を表示させることはできました。
どのように記載すれば全体表示できるのでしょうか。
MainActivity
public class MainActivity extends AppCompatActivity {
private AssetManager assetManager;
private ImageView imageViewbyCode;
private LinearLayout myLayoutP;
private final static String TAG = "MainActivity";
private GridView gridView = null;
ArrayList<String> listPath;
ArrayList<Bitmap> bitmapList;
GridViewAdpter gridViewAdapter;
@Override protected void onCreate (Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); toolbar.setLogo(R.mipmap.ic_launcher); setSupportActionBar(toolbar); CollapsingToolbarLayout toolbarLayout = findViewById(R.id.toolbarLayout); toolbarLayout.setTitle(getString(R.string.toolbar_title)); toolbarLayout.setExpandedTitleColor(Color.WHITE); toolbarLayout.setCollapsedTitleTextColor(Color.LTGRAY); gridView = (GridView) findViewById(R.id.gridviewframes); assetManager = getAssets(); bitmapList = new ArrayList<Bitmap>(); try { listAllImages(); } catch (Exception e) { } try { gridViewAdapter = new GridViewAdpter(MainActivity.this, bitmapList); gridView.setAdapter(gridViewAdapter); } catch (Exception e) { e.printStackTrace(); } } public void listAllImages(){ Bitmap bitmap = null; try{ String[] imgPath = assetManager.list("photos"); for(int i = 0; i< imgPath.length; i++){ InputStream is = assetManager.open("photos/"+imgPath[i]); Log.d(TAG, imgPath[i]); bitmap = BitmapFactory.decodeStream(is); bitmapList.add(bitmap); } }catch (IOException e){ Log.e(TAG, e.getMessage()); } }
}
GridViewAdapter
public class GridViewAdapter extends BaseAdapter {
Context mContext;
ArrayList<Bitmap> mImageArray; GridViewAdapter(Context context, ArrayList<Bitmap> imgArray) { this.mContext = context; mImageArray = imgArray; } @Override public int getCount() { return mImageArray.size(); } @Override public Object getItem(int position) { return mImageArray.get(position); } @Override public long getItemId(int position) { return 0; } @Override public boolean isEnabled(int i) { return true; } @Override public View getView(final int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View gridView; gridView = new View(mContext); gridView = inflater.inflate(R.layout.gridview, null); ImageView stickerImage = (ImageView) gridView.findViewById(R.id.sticker_item); stickerImage.setImageBitmap(mImageArray.get(position)); stickerImage.setScaleType(ImageView.ScaleType.FIT_XY); stickerImage.setLayoutParams(new ViewGroup.LayoutParams(300, 300)); return gridView; }
}
あなたの回答
tips
プレビュー