如何获取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);
}
}