简体   繁体   English

可扩展的列表视图组指示器向右

[英]Expandable listview Group indicator to right

I am trying to build an expandable listview, in which the group indicator should be placed to the right. 我正在尝试构建一个可扩展的列表视图,在该列表视图中应将组指示器放置在右侧。 The code I am using is 我正在使用的代码是

faq_ExpandableListView = (ExpandableListView)v. findViewById(R.id.lvExp);
setGroupIndicatorToRight();



private void prepareListdata(){

    listDataChild = new HashMap<String, List<String>>();
    HashMap<String, String> single_item;

    for (int i = 0; i < listDataHeader.size(); i++) {

      single_item = arraylist.get(i);

      List<String> comingSoon = new ArrayList<String>();
      comingSoon.add(single_item.get(AppConstants.faq_answers));

      listDataChild.put(listDataHeader.get(i), comingSoon);

    }

    populateListview();

}

private void populateListview(){
    listAdapter = new com.mawaqaa.babtain.adapter.ExpandableListAdapter(getActivity(), listDataHeader, listDataChild);

    // setting list adapter
    faq_ExpandableListView.setAdapter(listAdapter);
}

  private void setGroupIndicatorToRight() {
        /* Get the screen width */
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;

        faq_ExpandableListView.setIndicatorBounds(width - getDipsFromPixel(35), width
                - getDipsFromPixel(5));

    }

    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);
    }

The layout is 布局是

 <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        card_view:cardBackgroundColor="#fff"
        card_view:cardCornerRadius="8dp"
        android:id="@+id/cardview"
        android:layout_margin="15dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

           <ExpandableListView
            android:id="@+id/lvExp"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="3dp"
            android:layout_marginRight="3dp"
            android:groupIndicator="@drawable/settings_selector"
            android:divider="@android:color/transparent"
            android:cacheColorHint="#00000000"/>   

</android.support.v7.widget.CardView>

settings_selector for group indicator handling is 用于组指标处理的settings_selector是

      <?xml version="1.0" encoding="utf-8"?>
       <animation-list xmlns:android="http://schemas.android.com/apk/res/android" >

      <selector xmlns:android="http://schemas.android.com/apk/res/android">
           <item android:state_expanded="true" android:drawable="@drawable/up_arrow" />
          <item android:drawable="@drawable/down_arrow" />
    </selector>

   </animation-list>

You need to use setIndicatorBoundsRelative for API version 4.3 您需要将setIndicatorBoundsRelative用于API版本4.3

 private void setGroupIndicatorToRight() {
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;

        if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
             list_all_subscriptions.setIndicatorBounds(width - getDipsFromPixel(50), width - getDipsFromPixel(10));
        } else {
             list_all_subscriptions.setIndicatorBoundsRelative(width - getDipsFromPixel(50), width - getDipsFromPixel(10));
        }
 }

Hope it helps ツ 希望对你有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Expandable ListView图标(组指示器) - Android Expandable ListView Icon (Group Indicator) 当组在可扩展列表视图中没有子级时,是否为组隐藏指示器? - Hide Indicator For Group when group have no child in expandable listview? Android - 可扩展ListView如何在不影响其他人的情况下为组指示器设置动画 - Android - Expandable ListView how to animate group indicator without affect others 可扩展的列表视图组指示器在聚焦时自动更改 - Expandable listview group indicator change automatically when it get focused 如何在Expandable ListView中为子项为零的组设置无指示符? - How to set no indicator for the group having zero child in Expandable ListView? 如何将默认的可扩展列表组指示器从左向右移动? - How to move the default expandable list group indicator from left to right? 组指示器未出现在“可扩展列表”视图的右侧 - Group Indicator is not coming in the right side of Expandable List view 可扩展列表视图将组图标指示器向右移动 - Expandable list view move group icon indicator to right 可扩展列表视图在jellyBean 4.3版本中将组图标指示器移动到右侧? - Expandable list view move group icon indicator to right in jellyBean 4.3 version? 显示在错误组中的可扩展列表视图组视图指示器 - Expandable listview groupview indicator shown in wrong groups
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM