how to find in d.android.com?
Im new to this so much is a bit confusing now. But I see that d.android.com is a goldmine if you know how to use it and find the stuff.
How do I use this resource to find what Im searching for? To explain a bit how I mean. I have read a book with this code:
<LinearLayout...
...
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/on" />
I wanted to see what variables (right name?, like layout_gravity) ImageView could have and its attributes (?, like center_horizontal) so I checked out:
http://d.android.com/reference/android/widget/ImageView.html but nowhere I could find any of the above variables. So instead I tested to check its parent LinearLayout: http://d.android.com/reference/android/widget/LinearLayo开发者_如何学运维ut.html But there were nothing either of above variables. There was android:gravity thats looks alike tho.So how should I do to find which variables and its attributes a class (?, like imageview) can have?? Where/how do I find information like this??
First, everything you can set through XML can be set through code too, so this correspondence can help you.
Second, in the references the attributes (it's the name for XML "variables") are not always shown: only the ones that are particular of that class are, the others are inside an inherited XML attributes expandable section.
As an example, android:id
is an attribute in common with every class inheriting from View.
Third, LayoutParams
are a kind of their own: programmatically, you set a view's layout params with View.setLayoutParams(LayoutParams)
, and it's LayoutParams
that cointains those members/attributes. In XML this is represented by prepending layout_
, but it's only a convention.
The base class for LayoutParams
is ViewGroup.LayoutParams
. Every layout class adds something by extending it (for example, android:layout_gravity
is an attribute added by most of the layouts).
精彩评论