3

以下のコード スニペットを使用して、展開可能なリスト ビューのグループ インジケーターを変更しました。

ただし、グループ インジケーターが表示され、そのshrinked理由がわかりません。

expandablelistview は、ナビゲーション ドロワー内にあります。

コードとスナップショットが提供されます。

前もって感謝します。

インジケーターを右に移動するコード:

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>

グループ アイテムの 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" />

スナップショット:

問題の図

4

3 に答える 3

5

私も同じ問題を抱えていました。

次のようなグループ インジケーターを削除しました。

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;
}
于 2014-05-18T13:39:39.357 に答える
-1

このリンクに従ってください。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-08-23T10:10:53.670 に答える