1

我在应用程序的 ListActivity 中使用的自定义 ListView 有问题。我的问题是通过 ArrayAdapter 添加到 ListView 的所有 TextView 项目都显示在它们上方的灰色条上。我将包含显示的 ListView 的图像,但由于我没有 stackoverflow 站点要求的 10 的声誉,所以我不能。

用于生成 ListView 的布局文件(index.xml)定义如下:

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

    <ListView 
        android:divider="@color/mg_red" 
        android:dividerHeight="1sp"
        android:id="@android:id/list"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent" />


    <TextView 
        android:title="text_view"
        android:background="@drawable/listitemback"
        android:cacheColorHint="@drawable/listitemback"
        android:id="@+id/listItem"
        android:layout_width="fill_parent"    
        android:layout_height="fill_parent" 
        android:padding="10sp"    
        android:textColor="@color/listitemtext"
        android:textSize="16sp" />    

</LinearLayout>

用于显示列表的 ListActivity 代码如下:

public class IndexListActivity extends ListActivity
{
    private ListView m_listView = null;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {       
        try 
        {
            if (MGApplication.DEBUG_BUILD)
            Log.i("TMG", "IndexListActivity.onCreate");

        super.onCreate(savedInstanceState);

        // Get our global data object.
        MGApplication mgApp = (MGApplication) getApplication();

        // Set view layout
        SetContentView(R.layout.index);

        // Get references to our ListView and AdView objects
        m_listView = (ListView) findViewById(android.R.id.list);


            // Create a new ArrayAdapter object that will be used to initialize 
        // the underlying ListView object.
        ArrayAdapter<String> aa = new ArrayAdapter<String>(this, R.layout.index,
                                                               R.id.listItem,
                                                               mgApp.m_strAZRhymeNames);

        // Assign array adapter
        m_listView.setAdapter(aa);
        }        
        catch (Exception e)
        {
        }

        return;
    }   
}

非常感谢任何帮助,因为我对这个问题束手无策。我想我已经尝试了所有可以在网上找到的建议,但我无法删除灰色条。

谢谢你,

鲍勃

4

1 回答 1

0

您必须在test.xml文件中设置此属性。

     <ListView
            android:id="@+id/listview_middle"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="1dip"
            android:layout_weight="1"
            android:background="#ffffff"
            android:cacheColorHint="@android:color/transparent"
            android:choiceMode="singleChoice"
            android:scrollingCache="false" />

并在listview 对象中设置一些属性。

lv.setVerticalFadingEdgeEnabled(false);

在我这边,这是完美的工作。

于 2013-02-19T05:02:19.103 回答