I have android 2.1 project with a ListView in a LinearLayout. The LinearLayout has a background set to an image:
android:background="@drawable/background"
My intensions are to have the background alway visible through any data populated on the screen. It works, for the most part but I'm running into a couple quirks.
1) In the emulator the background fills the screen but on my phone it does not. I can see a tiny part of it at the top when the app starts and more is revealed as items are added to the ListView. I can see the background behind every row; just not where there isn't a row. How do I get it to fill the screen, even on my phone? It's Droid X, if that matters.
2) In the emulator when I hold down the button on a row and move the mouse over other rows the background disappears on the selected rows. On the phone, t开发者_如何学Gohis happens too. How do I always see the background?
You could use a FrameLayout and add..
- An ImageView with your background. Use e.g.
android:scaleType="centerCrop"
, so its scaled keeping the aspect ratio (layout_width
andlayout_height
both set tofill_parent
) - Your ListView (
layout_width
andlayout_height
both set tofill_parent
)
Wether you see the image behind the list view or not also depends on the list view element you use.
Also set the ListView's attribute android:cacheColorHint="#00000000"
(transparent)
Firstly, make sure you have not set the background property of the ListView
and its items.
Set the cache colour hint property of the ListView
to #000000 (blank).
You can either do this in xml using android:cacheColorHint="@color/blank".
Or in your code using ListView.setCacheColorHint(0)
For the first issue, I think you should make your listview to fill all the available space on the screen so that it maximizes its height e.g. android:layout_height="0dp" & android:layout_weight="1"
For the second issue, You should keep in mind that when ListView's item is focused, it shows its default colour. You can use selector on ListItems to make things more clear & better.
精彩评论