Question: When I developed, I found a new widget called `android.support.v7.widget.ButtonBarLayout` unexpectedly. I tried to search it on the internet, but nothing was found, even on the official development documents site. 

In the meantime, I found two `ButtonBarLayout` when I search `ButtonBarLayout` everywhere in **Android Studio**, one is `android.support.v7.widget.ButtonBarLayout` and the other is `com.android.internal.widget.ButtonBarLayout`. I tried to read source codes of both, I found that they are the same except package name. So I thought maybe `android.support.v7.widget.ButtonBarLayout` came from `com.android.internal.widget.ButtonBarLayout` after the **internal `ButtonBarLayout`** was through tests and released. At the same time, `ButtonBarLayout` is inherited from `LinearLayout`.

But there are some question:

* What can we get from `ButtonBarLayout` literally and how should we use it?
* I noticed the variable of `private boolean mAllowStacking`. When it changes, orientation of this layout would be changed. But I didn't really understand what it is used for.

So does somebody know `ButtonBarLayout` well?

P.S.: I used **Android Studio** of **2.0.0 Preview 4** and **Gradle Plugin** of **2.0.0-alpha3** and **Android Support Library** of **23.1.1** and **Platform-tools** of **23.1** and **Build-tools** of **23.0.2**.

Answer: 
As others pointed out, the class description tells exactly what it is: `an extension of LinearLayout that automatically switches to vertical orientation when it can't fit its child views horizontally.`

I might add that this was clearly done to fit with the [material design specifications](https://www.google.com/design/spec/components/dialogs.html#dialogs-specs) about dialogs. They make a distinction between *side by side* buttons and *stacked* buttons. See for example:

> 
> Side-by-side buttons are recommended when the text of each label does
>  not exceed the maximum button width, such as the commonly used
>  OK/Cancel buttons.
> 
> 
> 

[![enter image description here](https://i.stack.imgur.com/1dR4r.png)](https://i.stack.imgur.com/1dR4r.png)

While you should go for stacked buttons when the single button is too large, or there's not enough room for both:

> 
> When text labels exceed the maximum button width, use stacked buttons
>  to accommodate the text. Affirmative actions are stacked above
>  dismissive actions.
> 
> 
> 

[![enter image description here](https://i.stack.imgur.com/69s58.png)](https://i.stack.imgur.com/69s58.png)

So, one possible use of this class, is when designing your own dialogs. For example, `AlertDialog` and `AlertDialog.Builder` offer internal support for dialogs with buttons, but sometimes you just want to subclass `DialogFragment` or `AppCompatDialogFragment` for a better control.

There, it might be useful to setup a bottom button bar that follows the design guidelines, and have full control on the buttons (like enabling and disabling, things you can't do with an `AlertDialog` AFAIK).
<https://android.googlesource.com/platform/frameworks/base/+/master/core/java/com/android/internal/widget/ButtonBarLayout.java>

Looking into the code, I think it's a LinearLayout for buttons (duh). You can probably look at it like the Dialog buttons divided by a vertical spacer: | . AllowStacking will change the orientation to vertical and the gravity to the right instead of bottom. I should try it out to give a better answer