How do I insert an image in an activity with android studio? - android

I am very new to android development, and have only read and completed the first guide in the android development site. The problem I have been having is that I can not put a picture in an activity. I have the picture in my drawables folder. I just don't know how to get it on the screen. Any help is appreciated.

since you followed the tutorial, I presume you have a screen that says Hello World.
that means you have some code in your layout xml that looks like this
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
you want to display an image, so instead of TextView you want to have ImageView. and instead of a text attribute you want an src attribute, that links to your drawable resource
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/cool_pic"
/>

I'll Explain how to add an image using Android studio(2.3.3). First you need to add the image into res/drawable folder in the project. Like below
Now in go to activity_main.xml (or any activity you need to add image) and select the Design view. There you can see your Palette tool box on left side. You need to drag and drop ImageView.
It will prompt you Resources dialog box. In there select Drawable under the project section you can see your image. Like below
Select the image you want press Ok you can see the image on the Design view. If you want it configure using xml it would look like below.
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/homepage"
tools:layout_editor_absoluteX="55dp"
tools:layout_editor_absoluteY="130dp" />
You need to give image location using
app:srcCompat="#drawable/imagename"

When you have image into yours drawable gallery then you just need to pick the option of image view pick and drag into app activity you want to show and select the required image.

copy the image that you want to show in android app and paste in drawable folder. given below code
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/image"
/>

Related

ImageView doesn't appear

I have dragged an ImageView to layout and I selected the picture. But when I execute the application, It doesn't appear. What can I do to solve this ?
ImageView XML code;
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
app:srcCompat="#mipmap/idlepoor_moneys"
android:id="#+id/imageView4"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
Add this property in Your image View
android:src="#mipmap/idlepoor_moneys"
Remove the following line from your code
app:srcCompat="#mipmap/idlepoor_moneys"
As allready said change
app:srcCompat="#mipmap/idlepoor_moneys"
to
android:src="#mipmap/idlepoor_moneys"
Also I recommend to put your images in the #drawable folder. The mipmap is where app icons are stored when making an app.
app:src="#drawable/idlepoor_moneys"
You can easily find the drawable from your project map. If you can't find it you can always right click the folder to get the path to it.

How to display down arrow symbol android?

I have Button in my layout,in that I want to display a down arrow symbol. I defined the Button in a layout file How can I set the down arrow symbol to that button,
can anyone help, thanks in advance......
Taken from the Android API guides on Buttons, you can use an ImageButton.
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/down_arrow_icon"
... />
You can download the down_arrow_icon from a number of resources (like the Google Material icons page) or even create your own image.
Simply use android:drawableRight property. Like:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#drawable/your_drawable"/>

Image loading in android studio

I am not able to load the image. I tried the following
put the image in the drawable folder
then use the Image View tag
then able to load the picture for the app's icon, but not able to if I try to use picture inside my application.
what should I do to use a picture inside the created application
If you want to use an image from drawables you shold reference it from your layout via ImageView control:
<ImageView
android:id="#+id/this-is-your-image-view-id"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1.00"
android:src="#drawable/this-is-your-drawable-name" />
I faced the same problem,fixed by using .png image,not other format .

How to create a filled screen ImageView

I want to create a activity that looks like the gallery or whatsapp image view
I want the image to got displayed in its normal size and allow users to zoom in and out inside the ImageView so he can see the details of the image (which will contain text so i need to have zooming)
Please help cause i need this fast
This library provides zooming ImageViews.
Here is another great library i use.
https://github.com/sephiroth74/ImageViewZoom
Simply use this in xml instead of regular ImageView like this:
<your_package_name.ImageViewTouch
android:id="#+id/image_hq"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:contentDescription="#string/image_hq"
android:scaleType="matrix" />

How to show a picture?

I'm having a problem calling a picture to view. In my app after they click the button i want to take them to a new page where it will display a picture and under it some text. For this example say i want a pic if dog to be at the top of the page then under it say i want something like the breed and the cost of breed. Can anyone help me?
Use this XML for your page what will display the image:
<ImageView
android:id="#+id/image"
android:src="src"
/>
<TextView
android:text="image text"
android:layout_below ="#id/image"
/>
Of course, add more options to the views
Some good references:
http://developer.android.com/reference/android/widget/ImageView.html
http://developer.android.com/reference/android/widget/TextView.html
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
Use ImageView.
Also for other questions like this, I highly recommend reading the User Interface section of the online Android Developer's Guide.
In a layout XML, put a LinearLayout, oriented vertically, containing first an ImageView widget then a TextView widget. You can set the text using TextView#setText(String) and the image using ImageView#setDrawable(...).
This layout will be used by an activity that reads the Extra information (for example the text to show and the image URL or the image path on the SDCard) when it starts.
You should read more about Views on the Android developer's guide as advised by Shawn Lauzon.
write the above code in your .xml
<ImageView android:id="#+id/img"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center">
</ImageView>
and add this line in your .java class
img = (ImageView) findViewById(R.id.img);

Categories

Resources