在Android 2.3.3列表视图页脚背景 [英] List View Footer Background on Android 2.3.3
问题描述
这一个是怪异。我有一个列表视图即相对布局的一部分。我设置了一个背景,这个相对布局,并取得了列表视图的背景为透明。
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.
然后,我得到了Verizon的摩托罗拉Droid X更新2.3.3(这是2.2之前)。一旦它被更新了,我又开始了我的应用程序,现在这里是发生了什么。
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.
如果我的列表视图中只有一个排,我看到一个白色区域下方,而不是我的自定义背景。 但是,如果它有说100行,从而覆盖整个屏幕,我不会看到奇怪的白色背景。我相对布局具有高度和宽度设置为FILL_PARENT。
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".
我已经发布我的XML底部。有没有其他人遇到这个问题,或者我在做一些非常愚蠢的错误。
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>
编辑:
我想我已经找到了解决这个问题的:
I think I have found the solution to this problem:
改变了layout_height属性WRAP_CONTENT和它的工作就像一个魅力。 :)
Changed the layout_height attribute to wrap_content and it worked like a charm. :)
继变更线。
安卓layout_height =WRAP_CONTENT
Following the changed line.
android:layout_height = "wrap_content"
推荐答案
我写了一个类可以在Android的2.1 / 2用于将使用做正确的事在2.3反思与列表视图:
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();
}
}
使用它的XML如下:
<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"
/>
这篇关于在Android 2.3.3列表视图页脚背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!