开发者

How to determine appropriate dimensions for ExpandableListView groupIndicator icons?

开发者 https://www.devze.com 2023-02-03 23:11 出处:网络
I\'m working on an app that involves and ExpandableListView.We should like to replace the groupIndicator with one of our own choosing.

I'm working on an app that involves and ExpandableListView. We should like to replace the groupIndicator with one of our own choosing.

I created a spec for the indicator that would show a different png depending on the state of the selector (expanded or not expanded)

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

I then set up my layout xml to use开发者_如何学JAVA:

(Note that childDivider is a one pixel tall png rather than a color because setting that to a color seems to be bugged)

This works, except that our icon is stretched out vertically. That makes sense, because we just created a 25x25 icon and hoped for the best. I'm trying to figure out the dimensions of the native icon so that I can match it, but that's where I run into trouble.

Digging through the source code (ExpandableListView.java) I found that, by default, the class will use com.android.internal.R.styleable.ExpandableListView_groupIndicator. So I have an id, but no icon yet.

I'd love to be able to do:

Bitmap image = BitmapFactory.decodeResource(this.getResources(), com.android.internal.R.styleable.ExpandableListView_groupIndicator);
        imWidth = image.getWidth();
        imHeight = image.getHeight();

But as the "internal" suggests, it's not visible to me in user space.

I also found getIndicate() in ExpandableListView.java, but it is private, so I can't get to that either.

I'm quite new to diving into the platform source code, and I don't know how else to track down that image. Can anyone help me out?

Edit: Thanks CommonsWare. To spell out the rest for anyone else looking:

android:drawable/expander_group is defined in /frameworks/base/core/res/res/drawable/expander_group.xml.

expander_group.xml mentions that it uses @drawable/expander_ic_maximized and @drawable/expander_ic_minimized. Those drawables can be found in /frameworks/base/core/res/res/drawable/expander_ic_maximized.9.png and /frameworks/base/core/res/res/drawable/expander_ic_minimized.9.png, among other places for specific densities and such. The "9" explains why the default icons don't have distortion problems - they're patch-9 graphics. The density-agnostic versions of the icons are 34px by 38px.


base.git's core/res/res/values/styles.xml defines com.android.internal.R.styleable.ExpandableListView_groupIndicator as android:drawable/expander_group. That is a StateListDrawable in your SDK's copy of the resources. The underlying PNGs are of varying sizes based upon density.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号