我知道可以在可扩展的列表视图中创建自定义组指示器。我还知道,您可以通过使用setIndicatorBound()来定位默认组指示器。把这两种效果结合起来,是我没有看到的,也是我自己做不到的。
有谁知道这些可以一起完成的实际证据吗?
现在我可以创建一个自定义指示器并移动它。但是当我使用setIndicatorBounds时它总是移动到屏幕右边的一半。查看相关文章
我的问题是你真的能做到这一点吗?
我使用以下教程实现了这一点:http://android-adda.blogspot.com/2011/06/custom-expandable-listview.html
关键是这段代码:
DisplayMetrics metrics = new DisplayMetrics();
ExpandableListView expList = getExpandableListView();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
//this code for adjusting the group indicator into right side of the view
expList.setIndicatorBounds(width - GetDipsFromPixel(50), width -
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);
}