Pro-tip: layout_ attributes are instructions to the parent ViewGroup and found in its LayoutParams
When writing your layout XML files, you'll use a lot of different attributes to get things looking great. Looking up the documentation behind the attributes can give you a lot of insight into what exactly each does - but where do you find that documentation?
Take a look at a simple example:
</android.support.design.widget. AppBarLayout >
Your first thought in figuring out what app:layout_scrollFlags
does might be to look at Toolbar's documentation, but you'll find that Toolbars don't actually know anything about scrolling. The prefix layout_
denotes attributes that are instructions to the parent ViewGroup
- in this case, an AppBarLayout. But looking at the documentation of AppBarLayout still doesn't show that attribute. Hmm.
Turns out: those attributes are stored in what are called LayoutParams
- a helpful class associated with each View where the parent ViewGroup can store, you guessed it, parameters that affect how the ViewGroup will lay out that child View (such as how that view should react to scroll events). Every View has a getLayoutParams()
 method which must return a non-null value once a View is attached to a parent.
This also explains why it is so important to pass in a non-null parent to LayoutInflater.inflate()  - only then will the appropriate LayoutParams be created (passing null means all layout_ attributes will be effectively ignored!).
In this case, AppBarLayout.LayoutParams  is a custom subclass of LayoutParams that contains all of the information about the layout_
attributes (and their programmatic alternatives) that are specific to AppBarLayout - including the layout_scrollFlags!
This means that retrieving the LayoutParams involves casting the result of getLayoutParams() to the correct subtype based on the parent
of the View:
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
// Now you can call params.getScrollFlags() or params.setScrollFlags()
This also helps explain the difference between android:gravity
(instructions to the View on where to position its contents
) and android:layout_gravity
(instructions to the parent
ViewGroup on where to put the View).
 - http://developer.android.com/reference/android/view/View.html#getLayoutParams()
 - http://developer.android.com/reference/android/view/LayoutInflater.html#inflate(int,%20android.view.ViewGroup,%20boolean)
 - http://developer.android.com/reference/android/support/design/widget/AppBarLayout.LayoutParams.html