I tried to put background image to linearlayout in my android project. All is working nicely except those fading edges in the left and right on the screen. My background image dimensions are 52x602 and don't have such fading edge originally. I want the background image to cover all the area. Also it has done by designer and using 9-patch I think (black border around image). How can I set the background correctly without those edges?
In emulator it looks like this:
XML:
<?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:background="#drawable/login_background"
android:orientation="vertical"
>
</LinearLayout>
Ok, got answer myself. The .png files must have .9.png ending if they are 9-patch files...So if someone will have same problem, then you'll know.
Try setting fadingEdge to none
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/login_background"
android:orientation="vertical"
android:fadingEdge="none"
>
</LinearLayout>
Related
I have a simple ImageView that has layout_width="match_parent". It looks fine there is no margin or padding around the ImageView in the Android Studio, but when I run and test it with my phone an unwanted margin or padding appears around the ImageView. I searched for similar threads but didn't help. I also tried scale types, background color, and negative paddings. These didn't work either.
This problem also appears on all the layout types.
XML codes
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BlankFragment">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/hthtt" />
</FrameLayout>
Margin or padding around the ImageView appears on the tested phone
you need to set the background color(or other changes) in your drawable (#drawable/hthtt)....share drawable code
Here is my layout
<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:background="#drawable/backg"
android:paddingTop="40dp"
android:orientation="vertical"
tools:context=".AppleActivity" >
...
<LinearLayout>
I expect the background to fill the layout. But it leaves considerable space based on top and at the bottom. I don't mind if the background stretches. I just want it to fill the view. Does anyone know what might be causing this problem?
In case it's important: in my manifest file I am using android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" to hide the status bar.
try something like this..
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/backg"
android:orientation="vertical">
Have you tried adding
android:scaleType="fitXY"
into your linear layout? This will stretch your background image to linear layout bounds. You can also use centerCrop to fit the image to bounds without stretching it.
android:scaleType="centerCrop"
Also, use margin instead of padding.
I have an ImageView that when I look at in the XML preview layout on Eclipse looks fine, but when I launch the app on my hardware device a big whitespace comes to surround it. This is what the actual image is, without the whitespace that is being added. Here is my XML file too. How do I get rid of this whitespace?
Since your image shouldn't be too large, try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/linkMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="cat"
android:src="#drawable/ashsc" />
</LinearLayout>
This way, the image won't attempt to scale and won't create bounds outside the ImageView's image.
I should like to have an android app which has its background image on the bottom of the view.
Hopefully this could be achieved by only using XML.
My background image (bg.png) is located at the folder "res/drawable-mdpi".
The XML code is now:
<?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="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg"
android:layout_alignParentBottom="true"
android:layout_marginBottom="0dip" />
</LinearLayout>
But this is stretching the whole image over the whole page. I only want it stretched in horizontal direction.
The height has to be in proportion with the (stretched) width.
And this image has to be the background of a view/layout, I want to keep using the layout and add items/objects to it.
I hope someone could help me with this, I've been looking on the internet for it for a few hours and I couldn't find anything more helpful then I have now.
Thanks in advance,
Dennis
Firstly Change your LinearLayout to a RelativeLayout (android:layout_alignParentBottom only works with RelativeLayout).
Secondly use android:src="#drawable/bg" on your ImageView (not background)
if you really want to use the LinearLayout, you can try adding this attribute to your imageview android:layout_gravity="bottom"
The following code is almost the same thing I want to achieve.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg">
<ListView android:layout_height="wrap_content" android:id="#+id/levelList" android:layout_width="match_parent" android:layout_alignParentLeft="true"></ListView>
</RelativeLayout>
I want to setup a background image for the whole ListView. The problem of this code is that background image blinks or disappears on scrolling.
I use sdk 2.2 and an emulator to run the program.
You'll want to set android:cacheColorHint="#00000000" on your ListView. This will set the cacheColorHint to transparent (notice the extra 2 0's after #000000) and fix your problem. Alternatively you can set the cacheColorHint to #android:color/transparent.
You should read this page on ListView backgrounds.