I want to implement a splash screen for my app, i'm using this code to show the image, but the image is centered and not stretched to the whole screen. How can i solve that problem?
Thank you very much.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:src="#drawable/splash"
android:id="#+id/splash"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ImageView>
</RelativeLayout>
Try
<ImageView android:id="#+id/splash" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:src="#drawable/splash"
android:scaleType="fitXY" />
Where android:scaleType="fitXY"is responsible for stretching the image.
Related
When I restore an Activity from memory, I have a preview window for a couple of seconds.(Android OS just place it before loading all GUI stuff). I need to place a logo of an app in this preview window (I coded this as layout.xml) or make some splash screen (but not at the start of activity, but when it's restored).
To make situation more clear:
I have a layout with picture:
<?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:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="194dp"
android:layout_height="146dp"
android:src="#drawable/shell1" />
</RelativeLayout>
It looks like on this picture:
But, I can't use this layout for preview window. And if i use only image for preview window, I have something like that:
P.s. The second picture is not from preview window, it's just used to show the situation.
What should I do to have a proper nice look of preview window? To have this image just in the middle of screen. Thanks in advance.
This is for first Screen:
<?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:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="194dp"
android:layout_height="146dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/shell1" />
</RelativeLayout>
and this is for second Screen:
<?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:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/shell1" />
</RelativeLayout>
try using-
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/shell1" />
instead of -
<ImageView
android:id="#+id/imageView1"
android:layout_width="194dp"
android:layout_height="146dp"
android:src="#drawable/shell1" />
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 kept my image size as 320*480 but it shows blank space in vertical sides,Please give some advice.Here is my xml code please suggest me..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/ImageView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAlignBottom="true"
android:src="#drawable/splash" />
</LinearLayout>
add attribute android:scaleType="fitXY" to imageview
I have a square drawable image (drawable-l is 1280x1280) and I want it to crop depending on which direction the device is in (landscape, portrait). I want the image to always be centered, scaled to fill the largest side, and have the smaller side clipped.
Is this possible?
EDIT:
Adding on to Pramod J George's answer below, if you take the ImageView with the scaleType:centerCrop and put it along side your main layout inside of a FrameLayout, this will work perfectly!
<?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" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/background"
android:scaleType="centerCrop"
android:src="#drawable/background" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/logo"
android:src="#drawable/logo" />
</LinearLayout>
</FrameLayout>
I think this will do some help
http://blog.andresteingress.com/2011/09/22/to-scale-or-not-to-scale/
I've added an image to my xml file. This is the code that I am using:
<?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="fill_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/topbar_logo2x"
android:scaleType="fitStart" />
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<View
android:layout_width="fill_parent"
android:layout_height="0.5dip"
android:background="#000" />
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dip"
android:layout_marginRight="0dip" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
</LinearLayout>
I want my TabHost to be exactly on top of my image. When I checked up some answers in StackOverflow, I got an answer that stated to use
android:scaleType="fitStart"
I want to use both android:scaleType="fitStart" and android:scaleType="fitEnd" on the same ImageView and that is not possible as Sndroid will allow only one declaration of scaleType. How will I be able to attain the same with change in code ? Is there some other command that will help me?
Seems to me the larger black line must come from the image (topbar_logo2x) or the way it is scaled into the ImageView. Try using scaleType="fitXY" to see if the above black line vanishes. If not, then post the image for us to look.
Seems to me the View below LinearLayout causes the smaller black line. Remove it.