listfragments上的setCacheColorHint

时间:2011-11-28 20:16:35

标签: android android-layout

我正在使用Android兼容性库,我在使用非实体背景的listfragments时遇到了一些问题。问题与on this link描述的相同,但在this.listView()上调用setCacheColorHint没有任何影响。有没有人知道发生了什么?

<fragment class="com.mypackage.MyFragment"
android:id="@+id/my_fragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

并且在片段类中,恰好是ListFragment,我有

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {

    getListView().setCacheColorHint(android.R.color.transparent);
    super.onViewCreated(view, savedInstanceState);
}

谢谢,

2 个答案:

答案 0 :(得分:9)

您需要在getListView().setCacheColorHint(Color.TRANSPARENT)方法中添加onActivityCreated,而不是onViewCreated

答案 1 :(得分:0)

好的,我想我找到了让它发挥作用的方法。只需让片段膨胀自定义布局而不是使用自己的布局就可以了。

自定义layou只包含ListView。

我在这里附加了布局和onCreateView方法,以防它可以帮助其他人:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">

    <ListView android:id="@android:id/list" 
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent"
              android:listSelector="@android:color/transparent"
              android:cacheColorHint="#00000000" >
    </ListView>
</LinearLayout>

现在:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) 
{
    View res = inflater.inflate(R.layout.generic_list_layout, container, false);
    return res;
}
相关问题