Android Using Image as Background of ListView?
Rath开发者_Go百科er then setting list view to to particular background color I would like to fill the background with an image? How can this be done? Thanks
Any view's background can be a colour or an image or an XML-based drawable.
Put your image in your res/drawable folder, and in your layout XML set your ListView
to have an android:background="@drawable/myimage"
attribute.
Place the image in drawable folder which is under res folder and
set it as background to List view as Shown i below
<ListView android:id="@+id/mymovies" android:cacheColorHint="#cccccc"
android:layout_weight="1" android:scrollbars="vertical"
android:smoothScrollbar="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/imagename">
I confused with your question. Where you exactly want to set the backgroud image ? in listview or background at list item?
If you want to set background in listview items then you have to create a Custom listview
. Here you found an example to accomplish this: http://www.androidpeople.com/android-custom-listview-tutorial-example-part-2/
Try setBackgroundDrawable
or setBackgroundResource
.
As a general rule, if you want to add a background image to any kind of inflated list ArrayAdapter or BaseAdapter, then - Make sure that the background image is defined in the parent layout, or parent view, for example the main layout, using the attribute "android:background="@drawable/backupimage". Do not set the background in the XML representing the custom-row/object-view of the repeating instances.
This way the background image will be displayed only once, appearing static behind all inflated objects, and not duplicated again and again on every single row/object.
精彩评论