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"/>
Related
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!
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" />
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>
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
I have a large image myImage.png (its dims are 1536 x 784):
I want this image to be placed at the bottom of my layout scaled uniformly and fitting the width:
Layout is
<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" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/myImage"
android:adjustViewBounds="true"
android:layout_alignParentBottom="true"
android:scaleType="fitCenter" >
</ImageView>
</RelativeLayout>
I've tried dozens of combinations for layout_width, layout_height, adjustViewBounds and scaleType and nothing helped: it always looks as follows:
Help me please.
As someone says, use src instead of background:
<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" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/myImage"
android:adjustViewBounds="true"
android:layout_alignParentBottom="true"
android:scaleType="fitCenter" >
</ImageView>
</RelativeLayout>
You are using an ImageView. ImageViews use the src attribute to indicate which image to use and to apply the scaleType to.
background, is, as name suggests, merely a background attribute, made to be displayed on that whole background thing.
try this:
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/myImage"
android:adjustViewBounds="true"
android:layout_alignParentBottom="true"
android:scaleType="fitcenter" >
</ImageView>