Expandable watch list Move group icon icon icon right

As for the expandable view of the list, the icon of the group icon is located on the left, is it possible to move the indicator and place it to the right? Thank.

EDITED:. Since I don't want to extend the view, I got this solution to get the width dynamically. Just share your decision.

 Display newDisplay = getWindowManager (). GetDefaultDisplay (); 
 int width = newDisplay.getWidth ();
 newListView.setIndicatorBounds (width-50, width);
+58
android expandablelistview
Apr 27 2018-11-11T00
source share
13 answers

According to the source code of ExpandableListView , the only way to move the indicator to the right is to change its borders using the ExpandableListView.setIndicatorBounds() method. You can compute the associated onSizeChanged() method, for example.

+19
Apr 27 2018-11-11T00:
source share

setIndicatorBounds (int, int) does not work properly for Android 4.3. They introduced a new setIndicatorBoundsRelative (int, int) method, which works fine 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); } } 
+67
Aug 2 '13 at 9:53 on
source share

The best way to do this is below, but not for all versions of Android. Use the second or third method below.

 ViewTreeObserver vto = mExpandableListView.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mExpandableListView.setIndicatorBounds(mExpandableListView.getRight()- 40, mExpandableListView.getWidth()); } }); 

or that:

 @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); mExpandableListView.setIndicatorBounds(mExpandableListView.getRight()- 40, mExpandableListView.getWidth()); } 

will move this indicator to the right of viewing the list even on the device and on the tab.

or you can do it in a post-made branch.

  (new Handler()).post(new Runnable() { @Override public void run() { mExpandableListView.setIndicatorBounds(mExpandableListView.getRight()- 40, mExpandableListView.getWidth()); } }); 
+36
Feb 13 '12 at 11:01
source share

All XML solutions! I have found a better way to solve this problem. This does not require you to encounter display metrics; you do not need to hack it programmatically.

This is what you need to do:

1) set the layout direction from right to left

 <ExpandableListView ... android:layoutDirection="rtl" /> 

2) make sure that there is this in your layout of list items (yes, you need a custom layout):

 android:gravity="left" //to adjust the text to align to the left again android:layoutDirection="ltr" //OR this line, based on your layout 

And you are good to go!

+20
Jun 28 '16 at 2:52
source share

I tried using setIndicatorBounds and setIndicatorBoundsRelative, but the icon does not display as well as expected. Therefore, I change my code as follows:

create a group layout:

  <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="48dp" android:background="@drawable/header_selector" > <ImageView android:id="@+id/icon" android:layout_width="25dp" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="12dp" android:layout_marginRight="12dp" android:contentDescription="@string/desc_list_item_icon" android:src="@drawable/ic_home" /> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_toRightOf="@id/icon" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeightSmall" android:paddingRight="40dp" android:textAppearance="?android:attr/textAppearanceListItemSmall" android:textColor="@color/list_item_title" /> <TextView android:id="@+id/counter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginRight="8dp" android:background="@drawable/counter_bg" android:textColor="@color/counter_text_color" /> <ImageView android:id="@+id/icon_expand" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="200dp" android:layout_toRightOf="@+id/counter" android:contentDescription="@string/desc_list_item_icon" android:src="@drawable/navigation_expand" android:visibility="visible" /> <ImageView android:id="@+id/icon_collapse" android:layout_width="25dp" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="200dp" android:layout_toRightOf="@+id/counter" android:contentDescription="@string/desc_list_item_icon" android:src="@drawable/navigation_collapse" android:visibility="gone" /> </RelativeLayout> 

and using this layout in the adapter class inside the getGroupView method:

  @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { NavDrawerItem itemHeader = (NavDrawerItem) getGroup(groupPosition); LayoutInflater inflater = (LayoutInflater) this.context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = null; if (convertView == null) { view = (View) inflater.inflate(R.layout.drawer_header_item, null); } else { view = convertView; } ImageView icon = (ImageView) view.findViewById(R.id.icon); if (itemHeader.isIconVisible()) { icon.setImageResource(itemHeader.getIcon()); } else { icon.setVisibility(View.GONE); } TextView textTitle = (TextView) view.findViewById(R.id.title); textTitle.setText(" " + itemHeader.getTitle()); TextView textCount = (TextView) view.findViewById(R.id.counter); if (itemHeader.getCounterVisibility()) { textCount.setText(itemHeader.getCount()); } else { textCount.setVisibility(View.GONE); } ImageView iconExpand = (ImageView) view.findViewById(R.id.icon_expand); ImageView iconCollapse = (ImageView) view .findViewById(R.id.icon_collapse); if (isExpanded) { iconExpand.setVisibility(View.GONE); iconCollapse.setVisibility(View.VISIBLE); } else { iconExpand.setVisibility(View.VISIBLE); iconCollapse.setVisibility(View.GONE); } if (getChildrenCount(groupPosition) == 0) { iconExpand.setVisibility(View.GONE); iconCollapse.setVisibility(View.GONE); } return view; } 

Using this method, you can correctly adjust the position of the expand / collapse icon. hope this helps.

+10
Dec 05 '13 at 8:16
source share

Expandable list view move group icon indicator to right

setIndicatorBounds(int left, int right) used to set indicator boundaries for a group view of expandable .

 explvList.setIndicatorBounds(width-GetDipsFromPixel(35), width-GetDipsFromPixel(5)); 

Here, width means the width of the device.

 /Convert pixel to dip public int GetDipsFromPixel(float pixels) { // Get the screen density scale final float scale = getResources().getDisplayMetrics().density; // Convert the dps to pixels, based on density scale return (int) (pixels * scale + 0.5f); } 

FYI : The width is equal to the width specified in the setBounds method . Here, in my fragment, it's 35. Another wise icon is broken. For more details you can visit here.

https://developer.android.com/reference/android/widget/ExpandableListView.html#setIndicatorBounds(int , integer)

https://developer.android.com/reference/android/widget/ExpandableListView.html#setIndicatorBoundsRelative(int , integer)

+2
Jun 08 '15 at 8:49
source share
 FIX: 

They introduced a new method in API 18 onwards, a method called setIndicatorBoundsRoundsative (int, int). You should check the version of Android and use the appropriate methods with the API:

 expListView = (ExpandableListView) v.findViewById(R.id.laptop_list); metrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); width = metrics.widthPixels; if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) { expListView.setIndicatorBounds(width - GetDipsFromPixel(50), width - GetDipsFromPixel(10)); } else { expListView.setIndicatorBoundsRelative(width - GetDipsFromPixel(50), width - GetDipsFromPixel(10)); } 
+2
Jul 03 '15 at 13:31 on
source share

if it is in the Fragment - onViewCreated ()

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

his work for me !. Hurrah!

+1
Mar 31 '16 at 11:43
source share

Enter this code in the Extensible Base Adapter.

 @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { ImageView imgs; String headerTitle = (String) getGroup(groupPosition); if (convertView == null) { LayoutInflater infalInflater = (LayoutInflater) this._context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = infalInflater.inflate(R.layout.list_group, null); } TextView lblListHeader = (TextView) convertView .findViewById(R.id.lblListHeader); imgs = (ImageView) convertView .findViewById(R.id.img_list); lblListHeader.setTypeface(null, Typeface.BOLD); lblListHeader.setText(headerTitle); if (isExpanded) { imgs.setImageResource(R.drawable.up_arrow); } else { imgs.setImageResource(R.drawable.downs_arrow); } return convertView; } 
  • List item
+1
Aug 02 '17 at 7:24 on
source share

setIndicatorBounds(int left, int right) used to set the indicator boundaries for the ExpandableListView group view.

 explvList.setIndicatorBounds(width-GetDipsFromPixel(35), width-GetDipsFromPixel(5)); 

Here, width means the width of the device.

Convert pixel to plunge:

 public int GetDipsFromPixel(float pixels){ // Get the screen density scale final float scale = getResources().getDisplayMetrics().density; // Convert the dps to pixels, based on density scale return (int) (pixels * scale + 0.5f); } 
0
Aug 02 '17 at 7:26
source share

Found this way to get the indicator on the right side.

 <ExpandableListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/expandableListView" android:indicatorLeft="320dp" /> 
0
Sep 06 '17 at 6:10
source share

I use the following short snippet, inspired by this example , which requires two drawing options in a folder:

 if (isExpanded) { ListHeader.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.up, 0); } else { ListHeader.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.down, 0); } 

In any case, I had to make a goodKode decision to get rid of the standard arrows.

So, I would advise you to stick to a simple previously proposed solution, since this is the most minimalist and accurate approach.

0
Dec 13 '17 at 4:18
source share

Try this ... this code is for setting the indicator of the ExpandableList group on the right side of the view.

 private ExpandableListView expandableListView; DisplayMetrics metrics; int width; metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); width = metrics.widthPixels; expandableListView = (ExpandableListView) findViewById(R.id.expandableListView1); expandableListView.setIndicatorBounds(width - GetDipsFromPixel(50), width - GetDipsFromPixel(10)); 

And call this method,

 public int GetDipsFromPixel(float pixels) { // Get the screen density scale final float scale = getResources().getDisplayMetrics().density; // Convert the dps to pixels, based on density scale return (int) (pixels * scale + 0.5f); } 

The result is .. ExpandableList right side group indicator

-2
Feb 13 '14 at 12:09 on
source share



All Articles