Android 可扩展列表视图指示器显示标题高度?
我使用了一个可扩展的列表视图,在列表的右侧显示组指示器,在这个列表中,我的标题名是单行,我的输出如下 在上图中,我的指示器看起来不错。 在下图中,我的指示器看起来不好,它会扩展,为什么会发生这种情况 这是我的密码Android 可扩展列表视图指示器显示标题高度?,android,expandablelistview,indicator,Android,Expandablelistview,Indicator,我使用了一个可扩展的列表视图,在列表的右侧显示组指示器,在这个列表中,我的标题名是单行,我的输出如下 在上图中,我的指示器看起来不错。 在下图中,我的指示器看起来不好,它会扩展,为什么会发生这种情况 这是我的密码 mExpandableList = (ExpandableListView)findViewById(R.id.expandable_list); mExpandableList.setIndicatorBounds(width - GetPixelFromDips
mExpandableList = (ExpandableListView)findViewById(R.id.expandable_list);
mExpandableList.setIndicatorBounds(width - GetPixelFromDips(40), width - GetPixelFromDips(10));
xml是
<ExpandableListView
android:id="@+id/expandable_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:groupIndicator="@drawable/group_indicator" />
group_indicator.xml为
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/arrow_down" android:state_expanded="true"/>
<item android:drawable="@drawable/arrow_up"/>
</selector>
任何人都有这个想法……。在adapterClass的
getGroupView()
上充气时,请查看您在自定义的\u group\u layout.xml上使用的视图。指示器的视图可能有一个fill_父项,这就是为什么当您的组包含更多行文本时,您的项目会拉伸其图标
我用更复杂的方法解决这个问题,但它是有效的: 具有可扩展列表的布局文件片段:
<ExpandableListView
android:id="@+id/accordion"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:groupIndicator="@android:color/transparent"
android:scrollbars="none" >
</ExpandableListView>
列表组元素的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/accordion_main_background"
android:minHeight="50dip"
android:orientation="vertical"
android:padding="@dimen/screenPromoTaskRootPadding" >
<TextView
android:id="@+id/accordionTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dip"
android:layout_toLeftOf="@+id/accordionIndicator"
android:background="@color/accordionOrangeBackColor"
android:paddingLeft="2dip"
android:paddingRight="2dip"
android:textColor="@color/blackTextColor"
android:textSize="@dimen/accordMainTextSize" />
<ImageView
android:id="@+id/accordionIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/arrow_up_np" />
</RelativeLayout>
在活动中。adaptedDataCollection只是一个包含ExpandableListAdapter数据的列表。它也是Accordion实现的片段,所以列表组将在选择一个元素后折叠其他元素
ExpandableListView accordion = (ExpandableListView) findViewById(R.id.accordion);
accordion.setOnGroupClickListener(this);
@Override
public boolean onGroupClick(ExpandableListView paramExpandableListView, View paramView, int paramInt, long paramLong) {
ImageView icon=(ImageView)paramView.findViewById(R.id.accordionIndicator);
for (int i = 0; i < adapterDataCollection.size(); i++) {
if (i == paramInt) {
if (paramExpandableListView.isGroupExpanded(i)) {
paramExpandableListView.collapseGroup(i);
icon.setImageResource(R.drawable.arrow_up_np);
} else {
paramExpandableListView.expandGroup(i);
icon.setImageResource(R.drawable.arrow_down_np);
}
} else {
paramExpandableListView.collapseGroup(i);
icon.setImageResource(R.drawable.arrow_up_np);
}
}
paramExpandableListView.invalidate();
return true;
}
ExpandableListView accordion=(ExpandableListView)findViewById(R.id.accordion);
accordion.setOnGroupClickListener(此);
@凌驾
公共布尔值onGroupClick(ExpandableListView参数ExpandableListView、View paramView、int paramInt、long paramLong){
ImageView图标=(ImageView)paramView.findViewById(R.id.AccordinationIndicator);
对于(int i=0;i
您可以通过[图层列表]设置指示器高度
选择器
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/layer_shrink" android:state_expanded="true"/>
您应该为箭头使用9补丁图像。您可以参考下面的图片 对于向下箭头,您可以使用下图 别忘了在图像名称后面附加“.9”,如
“您的\u image\u name.9.png”您用于分组项目的布局是什么?@AlexBcn linearlayout………非常有用的答案!
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/layer_shrink" android:state_expanded="true"/>