gpt4 book ai didi

android - 可扩展 ListView 中的自定义图标具有扭曲的尺寸

转载 作者:行者123 更新时间:2023-11-29 14:49:05 26 4
gpt4 key购买 nike

我有一个需要自定义箭头的可扩展 ListView 。我尝试将 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

知道它们为什么会失真,以及如何解决吗?

最佳答案

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

将 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;

关于android - 可扩展 ListView 中的自定义图标具有扭曲的尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24761517/

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