Android ExpandableListView指示器未正确对齐

Android ExpandableListView指示器未正确对齐,android,expandablelistview,Android,Expandablelistview,我以编程方式创建了一个ExpandableListView,并对groupitems使用TextView。现在,我发现groupIndicator有一个问题,当在xml中声明ExpandableListView时,可能不会出现这个问题:该指示器直接绘制到groupItem的顶部(“no paddingTop”)。我在文本视图上使用了填充,因此指示器的高度似乎与文本视图不对齐。如何正确对齐指示器 Thx 编辑: 在自定义BaseExpandableListAdapter中: @Override p

我以编程方式创建了一个ExpandableListView,并对groupitems使用TextView。现在,我发现groupIndicator有一个问题,当在xml中声明ExpandableListView时,可能不会出现这个问题:该指示器直接绘制到groupItem的顶部(“no paddingTop”)。我在文本视图上使用了填充,因此指示器的高度似乎与文本视图不对齐。如何正确对齐指示器

Thx

编辑: 在自定义BaseExpandableListAdapter中:

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    Context c = context.get();
    if(c==null)
        return null;
    if(convertView==null){
        convertView = new TextView(c);
        TextView t = (TextView) convertView;
        t.setText(groupData.get(groupPosition));
        t.setPadding(left, groupPadding, left, groupPadding);  // left '=' android.R.attr.expandableListPreferredItemPaddingLeft
        t.setTextSize(TypedValue.COMPLEX_UNIT_PX, groupTextSize);
        t.setTextColor(Color.WHITE);
        return t;
    }
    TextView t = (TextView) convertView;
    t.setText(groupData.get(groupPosition));
    return t;

}
这是一个未展开的groupItem的屏幕截图:

如您所见,指示器drawable接触到groupItem的上边缘

编辑2: 我设置了一个自定义可绘制的指示器,希望它能解决我的问题。起初,我的拖鞋被拉伸到适合groupItem的高度。我现在使用了9个补丁,可以防止指示器拉伸,但这会导致指示器与底部对齐(而不是像以前那样与顶部对齐)。好吧,还是同样的问题刚好相反。有没有办法用我的定制绘图工具解决这个问题?也许有一种方法可以将填充添加到指示器中(因为我知道可绘制高度和groupItem的高度)

//indicator_selector.xml:
//在MainActivity.onCreate()中
expView=新的ExpandableListView(上下文);
indicator=context.getResources().getDrawable(R.drawable.indicator\u选择器);
expView.setGroupIndicator(指示器);
expView.setIndicatorBounds(expView.getPaddingLeft(),expView.getPaddingLeft()+indicator.getIntrinsicWidth());

根据这个问题和coderat的答案,我想出了如何使用9patches[]解决我的问题:


显示一些代码。截图将是一个不错的奖励。
//indicator_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_expanded="true" android:drawable="@drawable/arrow_right" />
    <item android:drawable="@drawable/arrow_down" />

</selector>

//in MainActivity.onCreate()
expView = new ExpandableListView(context);
indicator = context.getResources().getDrawable(R.drawable.indicator_selector);
expView.setGroupIndicator(indicator);
expView.setIndicatorBounds(expView.getPaddingLeft(), expView.getPaddingLeft()+indicator.getIntrinsicWidth());