Android:在可扩展列表视图中设置Drawable

时间:2013-12-21 07:33:21

标签: android expandablelistview

在我的应用程序中,我有一个可扩展的列表视图,我想要使用另一个drawable更改可扩展列表视图上的组箭头,但不显示任何内容。 这是我的代码,我该如何解决?

<ExpandableListView
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/expandableListView"
            android:groupIndicator="@drawable/group_indicator"/>

group_indicator.xml:

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_empty="true" android:drawable="@drawable/arrow_up"></item>
        <item android:state_expanded="true" android:drawable="@drawable/arrow_down"></item>
        <item android:drawable="@drawable/arrow_up"></item>
</selector>

ParentActivity.java:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final ParentActivity thisActivity = this;
        setContentView(R.layout.backup_list);
        ActionBar actionBar = getSherlock().getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        // get the listview
        expListView = (ExpandableListView) findViewById(R.id.expandableListView);
        expListView.setIndicatorBounds(width - GetDipsFromPixel(50), width - GetDipsFromPixel(10));
....
}



 public int GetDipsFromPixel(float pixels)
    {
        // Get the screen's density scale
        final float scale = getResources().getDisplayMetrics().density;
        // Convert the dps to pixels, based on density scale
        return (int) (pixels * scale + 0.5f);
    }

编辑:

enter image description here

0 个答案:

没有答案