How to create a filled screen ImageView - android

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" />

Related

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

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"
/>

Preview Image of Custom View in Eclipse

Is it possible to set an image, for a custom "View" or "Control" to be shown in Eclipse? So that it somehow loads the image of the View so it can be previewed before adding it? Say for an open Library of Views, this would be ideal and good. I have no clue where to start looking.
To clarify, when going under "Form Widgets" there are preview of the controls like Buttons, TextView, RatingBar for example. Only this functionality for a control. I'm not sure if it's Eclipse specific, but...
Any ideas?
Yes you can use ImageView try below code in xml file:
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/icon" />
Yes, It is possible.
Here my CustomView (which extends ImageView)

How can I stretch the image in imagebutton to the whole area of the imagebutton?

Here is a picture that will help you understand my problem:
I want to stretch the image shown inside ImageButton to the whole area of the ImageButton.
As you can see, the picture with the number 1 only take about 95% of the ImageButton and you can also see the boundaries of the ImageButton.
I still want to maintain the image button style
Here's how I am using ImageView:
<ImageButton
android:id="#+id/secondActivityBbuttonDownRight"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:scaleType="fitStart"
android:src="#drawable/111" />
I think I found out what is my problem.
I need a custom component that can contain only an image and have a clicking effect.
ImageButton is ImageView.
If you want your image to fill button
than set android:scaleType="fitXY", so the image you set in android:src will be stretched to fill whole image button.
ImageButton has a background under your image and padding.
If you do not want background
set android:background="#android:color/transparent".
If you do not want padding
set android:padding="0" or set background without padding.
You can also use
android:scaleType="centerCrop"
android:padding="0dp"
android:scaleType="fitXY" tested and works correctly.
Use below code :-
<ImageButton
android:id="#+id/secondActivityBbuttonDownRight"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:scaleType="fitStart"
android:background="#drawable/111" />
You should consider creating a 9-patch image to make the image fit correctly on an ImageButton in case you need to stretch it, but you don't want the image to become distorted.
To have a button with an image that completely covers it, you can use something like this:
<ImageButton android:id="#+id/iconBtn"
android:layout_width="64dip"
android:layout_height="64dip"
android:src="#drawable/icon_button"
android:scaleType="fitCenter"
android:background="#00000000"/>
For a full tutorial on creating buttons with custom skins and the use of selectors to manage their states, you can check a tutorial I've written some time ago here (Creating a custom Android button with a resizable skin).
If your image "111" has no padding itself then simply use android:background"#drawable/111"
Just set this two attributes on the ImageButton:
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="centerCrop"
With those, you will get the provided src to be stretched, and also if you put some specific width and height on that ImageButton you won't get a rectangle around it.

Android Image Control

I have a big problem. I want to create a control for android in which the user sees an image and over lapping this image are smaller icons/image which are positioned relative to background image.
The smaller icons can be selected.
I really do not know how to go about it.
You could do this by having a clean image as background, like this:
and then you could have TextViews within a RelativeLayout with the names for example, and on every textView you can set the attribute clickable to your method.
Something like this:
<TextView
android:id="#+id/nevada"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/Oregon"
android:layout_marginRight="50dp"
android:layout_marginTop="21dp"
android:layout_toLeftOf="#+id/Cali"
android:clickable="true"
android:onClick="showState"
android:text="#string/Nevada"
android:textColor="#color/contact_map_text_color" />
and on your activity/fragment you will have your method that will be called by the View, in the example case: "showState"
Edit: its probably not the best approach but it certainly works

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