gpt4 book ai didi

android - 更改 ExpandableListView 中的可扩展指示器

转载 作者:IT王子 更新时间:2023-10-28 23:51:28 25 4
gpt4 key购买 nike

尝试创建 ExpandableListView。组的初始 View 显示良好。但是,当我单击列表项时,我的箭头不会改变。请参阅下面的图片。

enter image description here

如何改变箭头的方向?

布局 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>

最佳答案

可扩展的 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 这里我正在使用这样的 setindicator 代码,这很好用

 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>

关于android - 更改 ExpandableListView 中的可扩展指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15501413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com