Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List View Footer Background on Android 2.3.3

Tags:

This one is weird. I have a list view that is a part of Relative Layout. I have set a background to this Relative Layout and made list view background as transparent.

Now, everything was working great till this morning. I could see the whole screen covered with my custom background even if there is just one row in my list view.

Then, I got update on Verizon Motorola Droid X for 2.3.3 (it was 2.2 before). Once it was updated, I started my app again and now here is what happens.

If my list view has only one row, I see a white area below it and not my custom background. But if it has say 100 rows and thus covers the whole screen I won't see that weird white background. My relative layout has width and height set to "fill_parent".

I have posted my XML at the bottom. Has anyone else faced this problem or I am making some really stupid mistake.

<RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:background = "@drawable/background"      android:layout_width="fill_parent"     android:layout_height="fill_parent">     <ListView   android:id = "@+id/listQueue"                 android:layout_width = "fill_parent"                 android:layout_height = "fill_parent"                 android:layout_below = "@id/homeScreenBanner"                 android:background="@android:color/transparent"                 android:divider="@drawable/separator"                 android:scrollingCache="false"/> </RelativeLayout> 

EDIT:

I think I have found the solution to this problem:

Changed the layout_height attribute to wrap_content and it worked like a charm. :)

Following the changed line. android:layout_height = "wrap_content"

like image 363
anargund Avatar asked Jun 02 '11 00:06

anargund


1 Answers

I wrote a class that can be used in Android 2.1/2 that will do the right thing in 2.3 using reflection with ListViews:

import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method;  import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Build; import android.util.AttributeSet; import android.widget.ListView;  public class TransparentListView extends ListView {      private void makeTransparent() {         if (Build.VERSION.SDK_INT >= 9) {             try {                  Method overscrollFooterMethod =                      TransparentListView.class.getMethod("setOverscrollFooter", new Class[] {Drawable.class});                 Method overscrollHeaderMethod =                      TransparentListView.class.getMethod("setOverscrollHeader", new Class[] {Drawable.class});                   try {                     overscrollFooterMethod.invoke(this, new Object[] {null});                     overscrollHeaderMethod.invoke(this, new Object[] {null});                 } catch (IllegalArgumentException e) {                     e.printStackTrace();                 } catch (IllegalAccessException e) {                     e.printStackTrace();                 } catch (InvocationTargetException e) {                     e.printStackTrace();                 }             } catch (SecurityException e) {                 e.printStackTrace();             } catch (NoSuchMethodException e) {                 e.printStackTrace();             }         }     }      public TransparentListView(Context context) {         super(context);         this.makeTransparent();     }      public TransparentListView(Context context, AttributeSet attrs) {         super(context, attrs);         this.makeTransparent();     }      public TransparentListView(Context context, AttributeSet attrs, int defStyle) {         super(context, attrs, defStyle);         this.makeTransparent();     } } 

Use it in XML as follows:

<com.myapp.TransparentListView android:id="@android:id/list"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:transcriptMode="alwaysScroll"     android:layout_weight="1"     android:dividerHeight="0dip"     android:divider="#00000000"     android:cacheColorHint="#00000000" />   
like image 167
esilver Avatar answered Oct 12 '22 01:10

esilver