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 Motorola 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. :)
遵循更改后的行.android:layout_height = "wrap_content"
推荐答案
我写了一个可以在 Android 2.1/2 中使用的类,它将在 2.3 中使用 ListViews 的反射来做正确的事情:
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 中使用它,如下所示:
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"
/>
这篇关于Android 2.3.3 上的列表视图页脚背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!