expandablelistview中的自定义图标具有扭曲的尺寸

时间:2014-07-15 14:57:35

标签: android xamarin xamarin.android expandablelistview

我有一个需要自定义箭头的expandablelistview。我尝试将groupIndicator设置为这样的选择器:

<ExpandableListView
            android:id="@+id/home_drawer_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:childDivider="@android:color/transparent"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:groupIndicator="@drawable/expandable_list_view_selector" />

<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_right" />
</selector>

但是,由于某种原因,这会扭曲箭头的尺寸,见下文:

enter image description here

知道为什么他们会被扭曲,以及如何解决它?

1 个答案:

答案 0 :(得分:3)

事实证明,问题是我在组头中的TextView上设置了填充,然后扭曲了图像。我发现整个默认的组头和自定义指示器使用起来非常麻烦,你可以在不扭曲图像的情况下真正自定义行,所以我最终使用了组头的自定义视图。 / p>

将ExpandableListView的groupIndicator设置为@null:

<ExpandableListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:groupIndicator="@null" />

添加自定义组标题,在我的情况下为ListViewGroupHeader.axml:

<?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="match_parent"
    android:padding="@dimen/padding">
    <ImageView
        android:id="@+id/group_header_arrow"
        android:src="@drawable/arrow_right"
        android:layout_centerVertical="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingRight="10dp" />
    <TextView
        android:id="@+id/group_header_title"
        android:layout_toRightOf="@+id/group_header_arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="@color/black"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_centerVertical="true" />
</RelativeLayout>

在适配器的GetGroupView方法中设置自定义布局,键入要显示的图像的isExpanded属性:

var layoutInflater = (LayoutInflater)ApplicationContext.Activity.GetSystemService (Context.LayoutInflaterService);
            var view = layoutInflater.Inflate(Resource.Layout.ListViewGroupHeader, null);
            var arrowImageView = view.FindViewById<ImageView> (Resource.Id.group_header_arrow);
            var titleTextView = view.FindViewById<TextView> (Resource.Id.group_header_title);

            arrowImageView.SetImageResource (isExpanded ? Resource.Drawable.arrow_down : Resource.Drawable.arrow_right);
            titleTextView.Text = title;
            if (isExpanded && colorExpandedBlue) {
                arrowImageView.SetImageResource (Resource.Drawable.arrow_down_blue);
                titleTextView.SetTextColor (ApplicationContext.Activity.Resources.GetColor (Resource.Color.standard_blue));
            }
            return view;