3

我已经使用下面的代码片段更改了可扩展列表视图的组指示器。

但是,组指示器出现了shrinked,我似乎无法弄清楚为什么。

expandablelistview 位于导航抽屉内。

提供代码和快照。

提前致谢。

代码向右移动指示器:

expListView = (ExpandableListView) getActivity().findViewById(
            android.R.id.list);
    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int width = metrics.widthPixels; 
    expListView.setIndicatorBounds(width - UIUtils.getPxFromDp(getActivity(), 40), width - UIUtils.getPxFromDp(getActivity(),20));   

更改指标的代码

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">            
       <item android:drawable="@drawable/ic_action_navigation_expand_black" android:state_empty="true">  </item>            
       <item android:drawable="@drawable/ic_action_navigation_collapse_black" android:state_expanded="true"></item>                
       <item android:drawable="@drawable/ic_action_navigation_expand_black"></item>
 </selector>

  <android.support.v4.widget.DrawerLayout
  .....
 <ExpandableListView 
    android:id="@android:id/list"
          android:layout_width="300dp"
          android:layout_height="match_parent"
          android:layout_gravity="left"
          android:background="@android:color/white"
          style="@style/ListViewMyApplynxTheme"
          android:groupIndicator="@drawable/explist_custom_group_indicator"
          android:divider="#D3D3D3"
          android:dividerHeight="1dp"/>
 </android.support.v4.widget.DrawerLayout>

组项的 XML 也与子项相同:

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

<ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/app_name"
    android:src="@drawable/ic_action_delete_black"
    android:layout_marginLeft="30dp" />

<TextView
    android:id="@+id/item"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="Menu Item"
    android:gravity="center|left"
    android:paddingLeft="10dp" />

快照:

问题说明

4

3 回答 3

5

我有同样的问题。

我删除了组指示器,例如:

android:groupIndicator="@null"

然后我在组头中放了一个 ImageView。在getGroupView()的适配器中,我为这个 ImageView 提供了与组指示器相同的功能:

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

        // initialize ImageView
        ImageView imgExpandCollapse = (ImageView) convertView.findViewById(R.id.imgExpandCollapse);

        // check if GroupView is expanded and set imageview for expand/collapse-action
        if(isExpanded){
            imgExpandCollapse.setImageResource(R.drawable.ic_action_collapse);
        }
        else{
            imgExpandCollapse.setImageResource(R.drawable.ic_action_expand);
        }

        return convertView;
}
于 2014-05-18T13:39:39.357 回答
1

To avoid the scaling you have to use nine-patch images instead of the regular png's: https://groups.google.com/forum/#!topic/android-developers/KfrpFr4kYOI

How to create 9-patch: http://developer.android.com/tools/help/draw9patch.html You can create it in any graphics editor or in the special tool located in sdk\tools directory. Do not forget name the file like your_file_name.9.png.

于 2015-04-21T20:51:09.133 回答
-1

按照这个链接。并给 setIntrinsicbounds(30, 10) 赋值;

https://androidrant.com/2013/03/02/expandablelistview-group-indicator-bounds-nonsense/

<selector xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:state_empty="true">
    <layer-list>
        <item
            android:left="0dp"
            android:right="0dp"
            android:top="10dp"
            android:bottom="10dp"
            android:drawable="@drawable/right">
        </item>
    </layer-list>
</item>

<item android:state_expanded="true">
    <layer-list>
        <item
            android:left="0dp"
            android:right="0dp"
            android:top="10dp"
            android:bottom="10dp"
            android:drawable="@drawable/down">
        </item>
    </layer-list>
</item>

于 2016-08-23T10:10:53.670 回答