Android background image not shown in device? - android

I add the following code to main.xml to set an image as a background image for my app:
android:background="#drawable/bg"
So main.xml looks like this:
<?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"
android:gravity="bottom|fill_vertical"
android:background="#drawable/bg0"
>
<EditText
android:id="#+id/edWord"
android:layout_width="fill_parent"
android:layout_height="53px"
android:textSize="20px"
android:singleLine="true"
android:hint=""
/>
<LinearLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:layout_weight="1"
>
<ListView android:id="#+id/lstWord"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
>
<ImageButton
android:id="#+id/btnGetText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="#drawable/get"
android:layout_weight="0.25"
/>
<ImageButton
android:id="#+id/btnFind"
android:text="Click me..."
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="#drawable/find"
android:layout_weight="0.25"
/>
</LinearLayout>
</LinearLayout>
And of course the image bg.png is in drawable.
The problem is that the background image is shown only in the emulator but not in my actual device (HTC Desire).
What have I done wrong? What do I need to do to solve this problem?
Can you guys there help? Thank you very much.

I found the problem . Just remove fill_parent from the main Linear Layout Gravity. No need to set background in the Listview as you do right now. Just Change as i suggest it solve your problem.
android:gravity="bottom|fill_vertical"

try this in place of that
<LinearLayout
xmlns:android= "http://schemas.android.com/apk/res/android"
android:id="#+id/linearlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg" />
</Linearlayout>

I got a similar bug my background drawable was shown in the graphical editor of eclipse but not on the devices I used for debugging.
-> For me it helped to clean the image (I just opened it in paint and saved it) after that i
overwrote the old image with the new one and copied it into the drawable folders.

Some lolipop devices wouldn't show with higher resolution images. You could also manually resize the bitmap programmatically if you generate the backgrounds randomly or use a set of images to load them into the background

Related

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>

Android Layout - Image taking up extra space

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.

I dont want change vertical-horizontal rate...:) Circle becomes ellipse.... HELP!

I want horizontal-vertical rate unchanged. How can ı Do this?? my picture is rate is 320x70.
for example, in my phone(samsung galaxy-s GT-I9000) it looks like 320x100. originally I have a circle but it look ellipse... ı have to fix it, but how can ı do??
its my code.`
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:background="#drawable/main"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/resandroid">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:layout_weight="5"></LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:layout_weight="3">
<ImageButton android:layout_weight="1" android:id="#+id/menu_mycameras"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#drawable/menu_cameras" android:cropToPadding="true">
</ImageButton>
<ImageButton
android:paddingTop="20px"
android:layout_weight="1" android:id="#+id/menu_aboutus"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#drawable/menu_aboutus" >
</ImageButton>
<ImageButton android:layout_weight="1" android:id="#+id/menu_help"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#drawable/menu_help">
</ImageButton>
</LinearLayout>
`
I'm assuming you're talking about your image scaling as fitXY. Just add android:scaleType="sometypehere", and pick a type that suits your needs. Set it to "none" and it won't scale your image at all, where "fitCenter" will scale it to fit proportionally.

My ListView backgrounds go black during scrolling - how to fix?

Ive specified white backgrounds for pretty much all widgets and it works, except when scrolling. The background container goes black during scrolling resulting in annoying flickering.
You will need to use the setCacheColorHint() method of ListView.
Example: list.setCacheColorHint(yourBackColor);
Explanation of the issue and solution here
ScrollingCache="false" in your activity's *.xml file for the list object should do the trick, too.
I fixed this problem by making the background color of the cells the same color as the ListView, so:
<?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"
android:background="#FFFFFF">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"> <---- Background color of ListView
</ListView>
</LinearLayout>
and then the row:
<?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"
android:padding="8dip"
android:background="#FFFFFF"> <--- Background color of the cell
<LinearLayout
android:id="#+id/projects_cover_row_image_layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:background="#444444"
android:layout_centerInParent="true"
android:layout_marginRight="8dip">
<ImageView
android:id="#+id/projects_cover_row_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:contentDescription="#string/projects_image_content"/>
</LinearLayout>
...
</RelativeLayout>
that completely got rid of the problem for me and seems like the best solution
Just put background on the top and no highlight or other bad effects simple and no need of hint or cache
in listview layout
android:background="#000000" for black background or android:background="#FFFFFF" for white
<?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:background="#000000"
android:orientation="vertical" >
<TextView
android:id="#+id/testscheck"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:layout_weight="1"
android:layout_gravity="left|center"
android:gravity="left"
android:textColor="#color/ics"
android:textSize="14sp"
/>
</LinearLayout>

Categories

Resources