Expandable list view move group icon indicator to right

前端 未结 16 2386
栀梦
栀梦 2020-12-04 08:56

As regards to expandable list view, the group icon indicator is positioned to the left side, can I move the indicator and positioned it to the right? Thanks.

相关标签:
16条回答
  • 2020-12-04 09:52

    setIndicatorBounds(int, int) does not work properly for Android 4.3. They introduced a new method setIndicatorBoundsRelative(int, int) which works ok for 4.3.

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
           mExpandableListView.setIndicatorBounds(myLeft, myRight);
        } else {
           mExpandableListView.setIndicatorBoundsRelative(myLeft, myRight);
        }
    }
    
    0 讨论(0)
  • 2020-12-04 09:56

    According to ExpandableListView's source code, the only way to move an indicator to the right side is to change its bounds using ExpandableListView.setIndicatorBounds() method. You can calculate bound in onSizeChanged() method, for example.

    0 讨论(0)
  • 2020-12-04 09:56

    if it is in Fragment - onViewCreated()

        ViewTreeObserver vto = Expnlist.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new      ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Expnlist.setIndicatorBounds(Expnlist.getMeasuredWidth() - 80, Expnlist.getMeasuredWidth());
            }
        });
    

    its works for me!. Cheers!

    0 讨论(0)
  • 2020-12-04 09:58

    First you have to remove group indicator from your xml

    <ExpandableListView
                android:id="@+id/expandableListView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/nav_header_height"
                android:background="@android:color/white"
                android:dividerHeight="0dp"
                android:focusable="false"
                android:groupIndicator="@null" />
    

    then do as follows in your custom adapter

    public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    
    if (isExpanded) {
        groupHolder.img.setImageResource(R.drawable.group_down);
    } else {
        groupHolder.img.setImageResource(R.drawable.group_up);
    }}
    
    0 讨论(0)
提交回复
热议问题