【问题标题】:ExpandableListview Group Indicator ProblemExpandableListview 组指示器问题
【发布时间】:2013-11-20 17:33:24
【问题描述】:

我已使用下面的代码 sn-ps 更改了可扩展列表视图的组指示器。

但是,组指示符出现shrinked,我似乎不明白为什么。

可扩展列表视图位于导航抽屉内。

提供代码和快照。

提前致谢。

代码向右移动指示器:

expListView = (ExpandableListView) getActivity().findViewById(
            android.R.id.list);
    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int width = metrics.widthPixels; 
    expListView.setIndicatorBounds(width - UIUtils.getPxFromDp(getActivity(), 40), width - UIUtils.getPxFromDp(getActivity(),20));   

更改指标的代码

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

  <android.support.v4.widget.DrawerLayout
  .....
 <ExpandableListView 
    android:id="@android:id/list"
          android:layout_width="300dp"
          android:layout_height="match_parent"
          android:layout_gravity="left"
          android:background="@android:color/white"
          style="@style/ListViewMyApplynxTheme"
          android:groupIndicator="@drawable/explist_custom_group_indicator"
          android:divider="#D3D3D3"
          android:dividerHeight="1dp"/>
 </android.support.v4.widget.DrawerLayout>

Group Item 的 XML 也同样用于子项:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="horizontal" >

<ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/app_name"
    android:src="@drawable/ic_action_delete_black"
    android:layout_marginLeft="30dp" />

<TextView
    android:id="@+id/item"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="Menu Item"
    android:gravity="center|left"
    android:paddingLeft="10dp" />

快照:

【问题讨论】:

  • 能否贴出groupe适配器的xml来调查这个问题
  • 您好,感谢您的回复。我只是用它编辑过。
  • 我认为您的图像所允许的空间比它的实际尺寸小(如果是 png),请尝试将您的 textView 的 android:layout_width="match_parent" 更改为 android: layout_width="wrap_content" 并在drawable的所有文件夹中制作指标的图像(带有这个android-ui-utils.googlecode.com/hg/asset-studio/dist/…的缩放图像)
  • 我也有同样的问题。你找到解决方案了吗?

标签: android listview expandablelistview


【解决方案1】:

我遇到了同样的问题。

我删除了组指示器,例如:

android:groupIndicator="@null"

然后我在组头中放了一个 ImageView。在 getGroupView() 的适配器中,我为这个 ImageView 赋予了与组指示器相同的功能:

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

        // initialize ImageView
        ImageView imgExpandCollapse = (ImageView) convertView.findViewById(R.id.imgExpandCollapse);

        // check if GroupView is expanded and set imageview for expand/collapse-action
        if(isExpanded){
            imgExpandCollapse.setImageResource(R.drawable.ic_action_collapse);
        }
        else{
            imgExpandCollapse.setImageResource(R.drawable.ic_action_expand);
        }

        return convertView;
}

【讨论】:

    【解决方案2】:

    为避免缩放,您必须使用九个补丁图像而不是常规 png: https://groups.google.com/forum/#!topic/android-developers/KfrpFr4kYOI

    如何创建 9 补丁:http://developer.android.com/tools/help/draw9patch.html 您可以在任何图形编辑器或位于 sdk\tools 目录中的特殊工具中创建它。 不要忘记将文件命名为 your_file_name.9.png。

    【讨论】:

      【解决方案3】:

      点击此链接。并给 setIntrinsicbounds(30, 10) 赋值;

      https://androidrant.com/2013/03/02/expandablelistview-group-indicator-bounds-nonsense/

      <selector xmlns:android="http://schemas.android.com/apk/res/android" >
      
      <item android:state_empty="true">
          <layer-list>
              <item
                  android:left="0dp"
                  android:right="0dp"
                  android:top="10dp"
                  android:bottom="10dp"
                  android:drawable="@drawable/right">
              </item>
          </layer-list>
      </item>
      
      <item android:state_expanded="true">
          <layer-list>
              <item
                  android:left="0dp"
                  android:right="0dp"
                  android:top="10dp"
                  android:bottom="10dp"
                  android:drawable="@drawable/down">
              </item>
          </layer-list>
      </item>
      

      【讨论】:

        猜你喜欢
        • 2016-07-17
        • 2013-08-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-07
        • 2017-01-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多