有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java可扩展列表视图能否移动自定义图标(指示器)?

我知道可以在可展开的列表视图中创建自定义组指示器。我还知道,您可以使用setIndicatorBound()定位默认组指示符。我没有看到,也无法实现的是将这两种效果结合起来

有谁知道有任何实际证据证明这些都可以同时进行吗

目前,我可以创建一个自定义指示器并移动它。但是当我使用setIndicatorBounds时,它总是移动到屏幕右侧的一半。检查此Related Post

我的问题是你真的能做到吗?有证据吗?我没有找到


共 (1) 个答案

  1. # 1 楼答案

    我通过以下教程实现了这一点: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);
        }