Android:Jelly Bean 或更高版本中的 setIndicatorBounds

标签 android api expandablelistview

我创建了一个带有自定义 ExpandableListView 的应用。它工作正常。但我已经读到,在 Jelly Bean setIndicatorBounds 中无法正常工作。我与:

  • minSdkVersion: 14
  • targetSdkVersion: 18

我已经试过了,但它给了我一个错误:

调用需要 API 级别 18(当前最低为 14):android.widget.ExpandableListView#setIndicatorBoundsRelative

    DisplayMetrics metrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int anchoPantalla = metrics.widthPixels;

    if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {

        expListView.setIndicatorBounds(anchoPantalla - GetDipsFromPixel(40), 
                anchoPantalla - GetDipsFromPixel(10));

    } else {
        expListView.setIndicatorBoundsRelative(anchoPantalla - GetDipsFromPixel(40), 
                anchoPantalla - GetDipsFromPixel(10));
    }

如何修复我的错误并使我的代码在 Jelly Bean 中正常运行?谢谢

最佳答案

...
      DisplayMetrics metrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int anchoPantalla = metrics.widthPixels;

    if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {

        expListView.setIndicatorBounds(anchoPantalla - GetDipsFromPixel(40), 
                anchoPantalla - GetDipsFromPixel(10));

    } else {
        JB_setIndicatorBoundsRelative(anchoPantalla - GetDipsFromPixel(40), 
                anchoPantalla - GetDipsFromPixel(10));
    }
}    
    ...

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
    private void JB_setIndicatorBoundsRelative(int left, int right)
    {
        expListView.setIndicatorBoundsRelative(left, right);
    }

关于Android:Jelly Bean 或更高版本中的 setIndicatorBounds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23561025/

相关文章:

java - ProgressDialog 出现得太晚

javascript - 如何同时追加和格式化行 Google Sheet API

android - ExpandableListView in ViewFlipper显示问题?

android - ExpandableListView 不追加 child

java - 将文件写入内部存储时崩溃

android - 插入 android.database.sqlite.sqliteconstraintexception 错误代码 19 约束失败时出错

android - 在 Google Play 上设置促销,价格低于 0.99 美元

php - 如何使用 API 管理 PayPal 订阅?

facebook - 从 URL 中识别 Facebook 用户 ID?

ExpandableListView 的 child 的android 奇怪的背景