android:更改用于导航的可扩展列表视图的指示器图标和大小

发布于 2024-12-18 11:28:11 字数 90 浏览 3 评论 0原文

我正在制作一个应用程序,其中我必须使用给定的图像来扩展列表视图。实际上,我正在谈论导航路径的指示器图标及其大小。任何人都可以告诉我如何更改该图像。任何帮助将不胜感激。

I am making an app in which i have to use given images for expandable list view .Actully i am talking of indicator icon and its size which navigate the path.Can anyone tell me how to change that image .Any help will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

撞了怀 2024-12-25 11:28:11

您可以使用以下代码:

<ExpandableListView android:id="@+id/android:list"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:layout_marginTop="10dp"
    android:groupIndicator="@drawable/settings_selector" />

... 其中 setting_selector 是:

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

You can use the following code:

<ExpandableListView android:id="@+id/android:list"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:layout_marginTop="10dp"
    android:groupIndicator="@drawable/settings_selector" />

... where the setting_selector is:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:drawable="@drawable/up_arrow" 
         android:state_empty="true" />
   <item android:drawable="@drawable/down_arrow" 
         android:state_expanded="true" />
</selector>
潇烟暮雨 2024-12-25 11:28:11
<ExpandableListView android:id="@+id/android:list"
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"
       android:layout_marginTop="10dp"
       android:groupIndicator="@drawable/settings_selector"
   />

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:drawable="@drawable/up_arrow" android:state_expanded="true"/>
   <item android:drawable="@drawable/down_arrow" android:state_expanded="false"/>
</selector>

忘了把

<item android:drawable="@drawable/down_arrow" android:state_expanded="false"/>

它放进去。
对我来说,android:state_empty 不起作用。

<ExpandableListView android:id="@+id/android:list"
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"
       android:layout_marginTop="10dp"
       android:groupIndicator="@drawable/settings_selector"
   />

And

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:drawable="@drawable/up_arrow" android:state_expanded="true"/>
   <item android:drawable="@drawable/down_arrow" android:state_expanded="false"/>
</selector>

He forgot to put

<item android:drawable="@drawable/down_arrow" android:state_expanded="false"/>

in it.
For me, android:state_empty not working.

何以心动 2024-12-25 11:28:11

这是设置组指示器的有效方法

<selector xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:state_empty="true">
    <layer-list>
        <item
            android:left="20dp"
            android:right="-30dp"
            android:top="120dp"
            android:bottom="10dp"
            android:drawable="@drawable/panier_plus">
        </item>
    </layer-list>
</item>

<item android:state_expanded="true">
    <layer-list>
        <item
            android:left="20dp"
            android:right="-30dp"
            android:top="120dp"
            android:bottom="10dp"
            android:drawable="@drawable/panier_minus"
             >
        </item>
    </layer-list>
</item>

this is efficient way to set group indicator

<selector xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:state_empty="true">
    <layer-list>
        <item
            android:left="20dp"
            android:right="-30dp"
            android:top="120dp"
            android:bottom="10dp"
            android:drawable="@drawable/panier_plus">
        </item>
    </layer-list>
</item>

<item android:state_expanded="true">
    <layer-list>
        <item
            android:left="20dp"
            android:right="-30dp"
            android:top="120dp"
            android:bottom="10dp"
            android:drawable="@drawable/panier_minus"
             >
        </item>
    </layer-list>
</item>

り繁华旳梦境 2024-12-25 11:28:11

如果您指的是展开/折叠组图标,那么

Drawable d = getResources().getDrawable(R.drawable.settings_selector);
//position it in the group layout by setting the bounds
//params are left and right bounds
myExpandableList.setIndicatorBounds(345,375);

myExpandableList.setGroupIndicator(d);

我不太确定指示器的大小,设置指示器边界可以影响指示器的宽度,但不会影响高度。

您可以通过将可绘制对象设置为 null 来删除指示器,然后在 ExpandableAdapter 的 getGroupView() 中使用图像视图来膨胀自定义布局。

public View getGroupView(int groupPosition, boolean isExpanded, View convertView,     ViewGroup parent) {
    View convertView = null;
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = inflater.inflate(R.layout.customLayout, null);

    return convertView;
}

尽管此方法需要一些额外的工作才能使指示器在组展开时发生变化,例如侦听器来判断特定组是否展开并相应地更改图像。

If you mean the expand/collapsed group icon then

Drawable d = getResources().getDrawable(R.drawable.settings_selector);
//position it in the group layout by setting the bounds
//params are left and right bounds
myExpandableList.setIndicatorBounds(345,375);

myExpandableList.setGroupIndicator(d);

I'm not too sure about the size of the indicator, setting the indicator bounds can affect the width of the indicator but not the height.

You could remove the indicator by setting the drawable to null, then inflate a custom layout with an image view in it in getGroupView() in the ExpandableAdapter.

public View getGroupView(int groupPosition, boolean isExpanded, View convertView,     ViewGroup parent) {
    View convertView = null;
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = inflater.inflate(R.layout.customLayout, null);

    return convertView;
}

Although this method would require some extra work to get the indicator to change when the group is expanded, such as a listener to tell whether or not a particular group is expanded and change the image accordingly.

給妳壹絲溫柔 2024-12-25 11:28:11

这是正确的,检查我的应用程序

<ExpandableListView
            android:id="@+id/expandableListView"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:indicatorLeft="?android:attr/expandableListPreferredItemIndicatorLeft"
            android:divider="@android:color/darker_gray"
            android:groupIndicator="@drawable/select_next"
            android:dividerHeight="0.5dp" />

使用下面这样的......

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

It's correct, check my app

<ExpandableListView
            android:id="@+id/expandableListView"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:indicatorLeft="?android:attr/expandableListPreferredItemIndicatorLeft"
            android:divider="@android:color/darker_gray"
            android:groupIndicator="@drawable/select_next"
            android:dividerHeight="0.5dp" />

Use follow below like this....

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
       <item android:drawable="@drawable/ic_add_black_24dp"
             android:state_empty="true" />
       <item android:drawable="@drawable/ic_remove_black_24dp"
             android:state_expanded="false" />
    </selector>
墨落成白 2024-12-25 11:28:11

尝试使用这个:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/ic_up_arrow" android:state_expanded="true" />
  <item android:drawable="@drawable/ic_down_arrow" android:state_pressed="false"/>
</selector>

Try using this:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/ic_up_arrow" android:state_expanded="true" />
  <item android:drawable="@drawable/ic_down_arrow" android:state_pressed="false"/>
</selector>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文