I am looking for the way to assign image src to image view control. I read few example and they says something src="@drawable\image"
but didn't understand this, also I want to assign image src at runtime by java code also want to apply default image in XML.
You can add ImageView and VideoView in RelativeLayout and set ImageView to invisible and VideoView to visible and vice-versa and you can play video on onClick.
If you want to display an image file on the phone, you can do this:
private ImageView mImageView; mImageView = (ImageView) findViewById(R.id.imageViewId); mImageView.setImageBitmap(BitmapFactory.decodeFile("pathToImageFile"));
If you want to display an image from your drawable resources, do this:
private ImageView mImageView; mImageView = (ImageView) findViewById(R.id.imageViewId); mImageView.setImageResource(R.drawable.imageFileId);
You'll find the drawable
folder(s) in the project res
folder. You can put your image files there.
You can set imageview in XML file like this :
<ImageView android:id="@+id/image1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/imagep1" />
and you can define image view in android java file like :
ImageView imageView = (ImageView) findViewById(R.id.imageViewId);
and set Image with drawable like :
imageView.setImageResource(R.drawable.imageFileId);
and set image with your memory folder like :
File file = new File(SupportedClass.getString("pbg")); if (file.exists()) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap selectDrawable = BitmapFactory.decodeFile(file.getAbsolutePath(), options); imageView.setImageBitmap(selectDrawable); } else { Toast.makeText(getApplicationContext(), "File not Exist", Toast.LENGTH_SHORT).show(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With