如何更改ExpandableListView组指示灯的位置? [英] How to change ExpandableListView group indicator position?

查看:434
本文介绍了如何更改ExpandableListView组指示灯的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在 ExpandableListView 组指标与填充更改为正确的。

I want to change the ExpandableListView group indicator to right with padding.

我使用的自定义接口将数据加载到 ExpandableListView

I used custom adapter to load data to ExpandableListView.

这是我的 ExpandableListView XML。

<ExpandableListView
    android:id="@+id/Ex_offers"
    android:layout_width="250dp"
    android:layout_height="400dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:childDivider="#00000000"
    android:groupIndicator="@drawable/settings_selector"
    android:listSelector="@android:color/transparent">

</ExpandableListView>

这是 GroupView XML

 <TextView
        android:id="@+id/lblListHeadertwo"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@drawable/transperant_bar"
        android:fontFamily="Lato"
        android:paddingLeft="15dp"
        android:textColor="#daac56"
        android:textStyle="bold"
        android:textSize="17sp"
        android:paddingTop="8dp"  />

这是ChildView XML

This is ChildView xml

 <TextView
        android:id="@+id/text_offers"
        android:layout_width="300dp"
        android:layout_height="20dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/transperant_bar"
        android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
        android:textColor="#daac56"
        android:textSize="14sp"/>

    <ImageView
        android:id="@+id/img"
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:layout_marginLeft="12dp"/>

这是输出图像,我想保证金设置这一指标。

This is the output image, I want to set margin to this indicator.

推荐答案

setIndicatorBounds(INT,INT)不正确的Andr​​oid 4.3的工作。
他们引入了一种新的方法 setIndicatorBoundsRelative(INT,INT)这对于4.3工作正常。

setIndicatorBounds(int, int) does not work properly for Android 4.3. They introduced a new method setIndicatorBoundsRelative(int, int) which works ok for 4.3.

public int GetPixelFromDips(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);
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int width = metrics.widthPixels; 
    if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
        explvList.setIndicatorBounds(width-GetPixelFromDips(35), width-GetPixelFromDips(5));
    } else { 
        explvList.setIndicatorBoundsRelative(width-GetPixelFromDips(35), width-GetPixelFromDips(5));
    }
}

这篇关于如何更改ExpandableListView组指示灯的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆