Image does not fill width in ImageView Android - android

Setting a photo to an ImageView does not work as i expect. It does not fill the width completely.
This is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
android:orientation="horizontal" >
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/imageCell"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_margin="5dp"
android:src="#drawable/unnamed" />
</LinearLayout>
I tried with android:layout_width="wrap_content" and still no change.
The first image is not shown completelly. The second one is in portraid mode and it's ok.
Thank you.

try setting
android:scaleType="fitXY"
to your imageView

Related

Rotate ImageView without clipping

I want to change rotation dynamically, bud i faced with the problem. I did simple code example of my problem
as you can see parent cuts off piece of my image view when i set rotate
click here to see emulator screen
xml very simple
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:id="#+id/image"
android:layout_width="100dp"
android:layout_height="100dp"
android:rotation="-10"
android:background="#color/teal_200"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
Actually I want my picture to scale and not go beyond the boundaries of the ImageView
I tried to find solution, but all of them didn't resolve my problem
image how i want to see it
I suggest to use parent layout for ImageView and set background:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/teal_200">
<ImageView
android:id="#+id/image"
android:padding="8dp"
android:layout_width="100dp"
android:layout_height="100dp"
android:rotation="-10"
android:src="#mipmap/ic_launcher" />
</FrameLayout>
</LinearLayout>
Hope it helps!

Removing space above and below ImageView in Android

Hello I need help as i Am adding an ImageView in my android xml file and i get an extra space above and below it i have tried to see the options that i can use to remove it one of them was adding android:adjustViewBounds="true"
but when i do that that it removes my action Bar completely below is my code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.fred.yebo.MainFragment">
<ImageView
android:id="#+id/yeboAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/dice"
/>
</RelativeLayout>
Try this attribute :
android:adjustViewBounds="true"
automatically scales the height of the View.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.fred.yebo.MainFragment">
<ImageView
android:id="#+id/yeboAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/cal" />
</RelativeLayout>
Please check this answer.
You can try with scaleType property of your imageView
android:scaleType="fitXY"
this line scale your image with size of your container.There are a few properties of scaleType you can try which will be better for your case.Hope to help you!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.fred.piku.MainFragment">
<ImageView
android:id="#+id/pikuAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/dice" />
</RelativeLayout>

NetworkImageView to occupy full width of screen

I am using com.android.volley.toolbox.NetworkImageView.
Image is coming from url.
I want to display image so that its width to occupy full width of screen not height because below image there is a caption which is a Textview.
Here is the activity's xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/black"
tools:context=".MainActivity" >
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Here is the items xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/photo_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="1dp"
android:src="#drawable/button_register" />
<TextView
android:id="#+id/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/photo_image"
android:layout_marginLeft="15dp"
android:text="Check"
android:textColor="#color/white" />
</RelativeLayout>
From the backend the image size is 300 X 200 pixels.
How to set imageview so that it can occupy full width of the screen.
Can anyone help?
NetworkImageView extends ImageView so you should be able to use everything that works with ImageView.
So, if you want your image to occupy full width and adjust its height so it maintains its aspect ratio (at least that's what I understood you wanted to do) use the adjustViewBounds property
Your xml will look like this:
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/photo_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="1dp"
android:src="#drawable/button_register"
<!-- add adjustViewBounds -->
android:adjustViewBounds="true" />

Background fit LinearLayout

I want the background picture not to be deformed, but everytime I try, ImageView appears in front of other UI elements.
I already tried with an image view android:src and scaleType=center,
and when I try with another layout, then I can't make the picture fit.
try settings scaleType=matrix, if that didnt help either then there is issues with intrinsic padding , i will post customImageview Then.
cheers!
Try this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:contentDescription="#string/xxxx"
android:src="#drawable/xxxx" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/xxxx"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/today"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="xxx"
android:textSize="xxsp" />
</RelativeLayout>
</LinearLayout>

android imageview takes extra black space

the imageview takes extra [black] space and i dont know why
ok this imageview should wrap content but instead..
photo explains the problem
this is the code
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/map" /><ImageView
android:id="#+id/blxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="-20dp"
android:src="#drawable/photo" />
<ImageView
android:id="#+id/blxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/blxx" />
</LinearLayout>
</ScrollView>
Try the below:
android:adjustViewBounds="true"
This will remove the extra padded space
first possible reason for your problem:
sometimes when the image is too small, it can't scratch anymore then some limit. after that limit - what happens is what you see - blank space claimed by the imageView where additional scratch of the image was expected. I advice you to take larger picture (with bigger resolution)
Second possible reason:
add to your imageView properties on the xml file the following attribute:
android:scaleType="fitXY"
android:layout_gravity="center"
Above line is centering the image to fit inside your ImageView. Try without it. If not, set gravity to "fill" and try again.
Also remove one of the duplicates of blxx as noted.
hope this ll help you
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_gravity="center">
<ImageView
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_content"
android:src="#drawable/map" />
</LinearLayout>
</ScrollView>

Categories

Resources