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).
You are right first of all. `ButtonBar` layout does not seem to be featured anywhere in the official Android documentation. I tried myself to search about it, but to no avail. However I have found some information which defines what is a `ButtonBar` layout and when to use it. Hopefully this will help you.

Most tutorials use the `Buttonbar` layout in a dialogbox or at the bottom of a screen to confirm or decline an option. The image below is a visual representation of how the `ButtonBar` layout has been used in a screen.

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

The screenshot above has the following layout xml:

```
<LinearLayout
    style="?android:attr/buttonBarStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/Button01"
        style="?android:attr/buttonBarButtonStyle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Show" />

    <Button
        android:id="@+id/Button02"
        style="?android:attr/buttonBarButtonStyle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Change" />
</LinearLayout>

<EditText
    android:id="@+id/myView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" >

    <requestFocus />
</EditText>

```

So essentially what Android is doing here is simply creating two buttons next to each other in a `LinearLayout` with each button having the match\_parent parameter set to the width. Hence each button takes half the size of the screen. Android have actually taken away the hassle of creating seperate buttons and positioning them correctly to fit different screens, by creating a simple widget handling this altogether.

As with the support library, Android have implemented this for developers using an earlier API. It is normal for them to use the support library for this purpose.

Hope this helps :)