更改ExpandableListView扩展指标指标、ExpandableListView

2023-09-12 21:41:11 作者:籃兲ブ塰

我试图创建一个ExpandableListView。同组的初始视图显示了罚款。然而,当我点击列表项,我的箭并没有改变。见下面的图片。

我怎样才能改变箭头的方向?

我的布局XML:

 < ExpandableListView
        机器人:ID =@ + ID / expandable_list
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =match_parent
        机器人:分隔=@空
        机器人:后台=#FFFFFF
        机器人:groupIndicator =@可绘制/ settings_selector
        机器人:transcriptMode =alwaysScroll/>
 

settings_selector.xml

 < XML版本=1.0编码=UTF-8&GT?;
<动画列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

<选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目
        机器人:可绘制=@可绘制/ arrow_down
        机器人:state_empty =真/>
    <项目
        机器人:可绘制=@可绘制/ arrow_right
        机器人:state_expanded =真/>
< /选择器>

< /动画列表>
 

解决方案

扩展列表视图

 < ExpandableListView
    机器人:ID =@ + ID / expandable_list
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:groupIndicator =@可绘制/ group_indicator
    机器人:transcriptMode =alwaysScroll/>
 
android的ExpandableListView滑动显示异常

setindicator 这里IAM期运用setindicator code这样这个工作不错

  DisplayMetrics指标=新DisplayMetrics();
    。getWindowManager()getDefaultDisplay()getMetrics(度量)。
    INT宽度= metrics.widthPixels;

 mExpandableList =(ExpandableListView)findViewById(R.id.expandable_list);
 mExpandableList.setIndicatorBounds(宽 -  GetPixelFromDips(50),宽度 -  GetPixelFromDips(10));

   公众诠释GetPixelFromDips(浮点像素){
    //获取屏幕的密度天平
    最终浮动规模= getResources()getDisplayMetrics()密度。
    //将DPS像素,基于密度规模
    返程(INT)(像素*规模+ 0.5F);
}
 

RES /绘制/ group_indicator

 < XML版本=1.0编码=UTF-8&GT?;

     <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
           <项目机器人:可绘制=@可绘制/ arrow_right机器人:state_empty =真正的> < /项目>
           <项目机器人:可绘制=@可绘制/ arrow_down机器人:state_expanded =真正的>< /项目>
           <项目机器人:可绘制=@可绘制/ arrow_right>< /项目>
     < /选择器>
 

I'm trying to create an ExpandableListView. The initial view with the groups shows up fine. However, when I click the list item, my arrow does not change. See the images below.

How can I change the arrow's direction?

I have the layout XML:

  <ExpandableListView
        android:id="@+id/expandable_list"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"            
        android:divider="@null"
        android:background="#ffffff"
        android:groupIndicator="@drawable/settings_selector"
        android:transcriptMode="alwaysScroll" />

settings_selector.xml:

 <?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:drawable="@drawable/arrow_down"
        android:state_empty="true"/>
    <item
        android:drawable="@drawable/arrow_right"
        android:state_expanded="true"/>
</selector>

</animation-list>

解决方案

expandable listview

 <ExpandableListView
    android:id="@+id/expandable_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:groupIndicator="@drawable/group_indicator"
    android:transcriptMode="alwaysScroll" />

setindicator here iam useing setindicator code like this this working nice

 DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int width = metrics.widthPixels; 

 mExpandableList = (ExpandableListView)findViewById(R.id.expandable_list);
 mExpandableList.setIndicatorBounds(width - GetPixelFromDips(50), width - GetPixelFromDips(10));  

   public int GetPixelFromDips(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);
}

res/drawable/group_indicator

  <?xml version="1.0" encoding="utf-8"?>

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