Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what ?android:attr/listPreferredItemHeight is doing and how?

Tags:

java

android

  • public static final int listPreferredItemHeight

Ok, of course I understand this part of the expression...listPreferredItemHeight is the preferred list item height.

But I really don't get these stuff. Anyone can point me to the right direction where I can read about that?

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

the example where I find this code is here https://android-developers.googleblog.com/2009/02/android-layout-tricks-1.html

EDIT: in the example at the link the code is android:layout_height="?android:attr/listPreferredItemHeight". What exactly does it mean?

like image 392
mt0s Avatar asked Oct 27 '11 22:10

mt0s


2 Answers

The marker "?" means that you are referring to a style attribute. So ?android:attr/listPreferredItemHeight simply means "use the value defined by the attribute called listPreferredItemHeight in the namespace android."

This attribute and its value are part of the Android framework, hence the "android" namespace.

like image 116
Romain Guy Avatar answered Oct 20 '22 23:10

Romain Guy


android:layout_height="?android:attr/listPreferredItemHeight"

?[<package_name>:][<resource_type>/]<resource_name> taken from Referencing Styles.

The ? is used for referencing style attributes, where as the more familiar looking@ is used for normal resources.

Style attribute resources reference values in the currently applied theme. So values may differ between different themes.

The value of listPrefferedItemHeight, found in the android package of the currently applied theme is returned to android:layout_height. The resource type attr in the line of code above is optional and can be omitted. Therefore, the following is also correct:

?android:listPreferredItemHeight

like image 36
JSON C11 Avatar answered Oct 20 '22 21:10

JSON C11