2011-02-27 81 views

答えて

9

使用setIndicatorBounds

グループ インジケータがこの影響を受けている、最小で(指標の描画範囲を設定し、子指標の境界を継承するように設定されている場合、子インジケータこの によって影響を受けます)。

-4

これを行う直接的な方法はありません。

mIndicatorLeftおよびmIndicatorRightは、インジケータアイコンの場所を処理するExpandableListViewクラスの2つのフィールドで、プライベートフィールドです。残念ながら、インジケータの位置は、期待どおりにきちんと定義されたレイアウトでは設定されませんが、ExpandableListViewのdispatchDraw()で決定されます。上/下とmIndicatorRightとmIndicatorLeftの値を使用して長方形が描画され、このRectにインジケータアイコンが描画されます。インジケータアイコンを移動するには、このRect objの 'indicatorRect'という位置を変更する必要があります。

は、あなたがこの例 http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html 変更例ではgetGenericViewで0までのTextViewパディングの値を()見ることができるもののアイデアを得るためには、インジケータは、テキストを重複することがわかります。

唯一の方法は、mIndicatorRightをitem.getRight()およびmIndicatorLeftをitem.getRight() - 'your icon size'に設定して、ExpandableListViewのソースコードを取得し、これらのmIndicatorRightおよびmIndicatorLeft値を設定することです。

+0

どれも正しくありませんここにあります。 – moonlightcheese

29

実際には簡単な方法があります。このようなグループビューに関連

  1. 編集してXML:

    <?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="35dp" 
    android:orientation="horizontal" > 
    
    <TextView 
        android:id="@+id/videos_explist_groupname" 
        android:layout_width="match_parent" 
        android:layout_height="?android:attr/listPreferredItemHeight" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:layout_toLeftOf="@+id/videos_group_indicator" 
        android:gravity="center" 
        android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft" 
        android:textAppearance="?android:attr/textAppearanceListItem" /> 
    
    <ImageView 
        android:id="@+id/videos_group_indicator" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_centerVertical="true" 
        android:src="@drawable/videos_chevron_collapsed" /> 
    
    </RelativeLayout> 
    

    ImageViewTextViewの右側にあるかを参照してください。

  2. 編集しExpandableListAdapterとして、以下:

    @Override 
    public View getGroupView(final int groupPosition, final boolean isExpanded, final View convertView, final ViewGroup parent) { 
        View v; 
        if (convertView == null) { 
         v = newGroupView(isExpanded, parent); 
        } else { 
         v = convertView; 
        } 
        bindView(v, mGroupData.get(groupPosition), mGroupFrom, mGroupTo); 
        ((ImageView) v.findViewById(R.id.videos_group_indicator)) 
         .setImageResource(isExpanded?R.drawable.videos_chevron_expanded:R.drawable.videos_chevron_collapsed); 
        return v; 
    } 
    

    あなたは簡単にグループ状態に対応する描画可能に設定することができます見ることができるように。

私は質問が長い時間前に尋ねられたことを知っていますが、これは誰かを助けるかもしれません。

+0

expandablelistviewのインジケータタグには何を入れますか? – Maxrunner

+5

'android:groupIndicator =" @ null "' –

+0

@Bicouは 'isExpanded? 'のエラーに直面しています... – NagarjunaReddy

5

expList = getExpandableListView(); 
metrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(metrics); 
width = metrics.widthPixels; 
//this code for adjusting the group indicator into right side of the view 
expList.setIndicatorBounds(width - GetDipsFromPixel(50), width - GetDipsFromPixel(10)); 

そしてGetDipsFromPixelこれを試してみてください。この

public int GetDipsFromPixel(float pixels) 
{ 
    // Get the screen's density scale 
    final float scale = getResources().getDisplayMetrics().density; 
    // Convert the dps to pixels, based on density scale 
    return (int) (pixels * scale + 0.5f); 
} 
+0

それは確かに私を助け、魅力のように動作します – dariusiv

関連する問題