如何获得PreferenceScreen线高?

时间:2016-02-15 08:53:08

标签: android subclass preferenceactivity

如何获取PreferenceScreen线高度取决于Preference子类中的xml?

public class MyPref extends Preference{

  @Override
  protected void onBindView(View view) {
    super.onBindView(view);
    // Here getTop() & getBottom() is 0:0

  }
}

编辑& ANSWER
来自:Android: how to get value of "listPreferredItemHeight" attribute in code?

值位于 float listPreferredItemHeight

public class MyPref extends Preference
{

    private float listPreferredItemHeight;

    @Override protected View onCreateView(ViewGroup parent) 
    {
        Context context = getContext();

        android.util.TypedValue value = new android.util.TypedValue();
        context.getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, value, true);
        android.util.DisplayMetrics metrics = new android.util.DisplayMetrics();
        ((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
        listPreferredItemHeight = value.getDimension(metrics);
    }
}

0 个答案:

没有答案