moving imageview at top - android

I have an image of size 519px X 420px that I want to place at the top of my android screen. Now there is some empty white space between my image and the header that I want to remove at all.
XML code:
<ImageView
android:src="#drawable/sitemakers_laptops"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Please see above screenshot and help me update my XML in such a way so that empty space between blue header and the image get completely vanished.
Thanks in advance!
Complete XML code as requested:
<FrameLayout 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="in.sitemakers.sitemakers.AboutFragment">
<ImageView
android:src="#drawable/sitemakers_laptops"
android:layout_width="match_parent"
android:scaleType="fitXY"
android:layout_height="wrap_content" />
</FrameLayout>

Try this ImageView.ScaleType
Options for scaling the bounds of an image to the bounds of this view.
Use android:scaleType="fitXY"
Scale the image using FILL.
<ImageView
android:src="#drawable/sitemakers_laptops"
android:layout_width="match_parent"
android:scaleType="fitXY"
android:layout_height="420dp" />

You can use android:scaleType="fitXY"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
orientation="vertical"
android:layout_height="match_parent">
<ImageView
android:src="#drawable/sitemakers_laptops"
android:layout_width="match_parent"
android:scaleType="fitXY"
android:layout_height="wrap_content" />
</LinearLayout>

Updated XML code for posting image just after header. We have to give static height of the image along with android scaleType.
<FrameLayout 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="in.sitemakers.sitemakers.AboutFragment">
<ImageView
android:src="#drawable/sitemakers_laptops"
android:layout_width="match_parent"
android:scaleType="fitXY"
android:layout_height="420dp" />
</FrameLayout>

Try this ImageView.ScaleType
Options for scaling the bounds of an image to the bounds of this view.
use android:scaleType="fitXY"
<ImageView
android:src="#drawable/sitemakers_laptops"
android:layout_width="match_parent"
android:scaleType="fitXY"
android:layout_height="wrap_content" />

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>

Image does not fill width in ImageView 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

Splash screen is stretching in Nexus 4

I pasted my code below: problem is the image is stretching......
<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=".SplashScreen"
android:background="#color/black" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:src="#drawable/splashscreen"/>
</RelativeLayout>
you should use 9 page image . You can generate 9-patch images from 9-path generator..
after that modify your imageView like as
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="#drawable/splashscreen"/>
Use wrap_content instead of match_parent:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/splashscreen"/>

Androird/Eclipse : Stretching an image to fit with screen borders

I have this 9-patch picture "Imageview3"
I want to add in my activity. I want the red arms to matchs perfecty with the borders of the screen.
But when I do SCALE:fitXy here is what I obtain
so as you can seem it doesn't work, I tried all the scales, I tried to stretch the image but it never fits.
Here is my code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="324dp"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:paddingTop="150dp"
android:paddingRight="0dp"
android:src="#drawable/diviseur" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="407dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/a1"
android:visibility="visible" />
</FrameLayout>
</LinearLayout>
thanks for the help
Remove android:scaleType="fitXY" and keep android:layout_width="match_parent". Try it.
Make sure your actual image doesn't have a white border around it. As in, make sure the arms are at the very end of your image.
Instead of using android:src="#drawable/diviseur", try using android:background="#drawable/diviseur". And also consider using android:layout_weight="1" attribute.
Try this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:src="#drawable/foo"
/>

Categories

Resources