Question: Is it possible to have LinearLayout with layout\_height="match\_parent" and layout\_width that would attribute to half the height?

I would then put those layouts in larger HorizontalScrollView and let layouts keep desired aspect ratio.

Is this possible without creating my own layout that would handle it ?

Answer: 
You need a custom ViewGroup for this. Google has one called [ProportionalLayout](https://android.googlesource.com/platform/packages/apps/ContactsCommon/+/master/src/com/android/contacts/common/widget/ProportionalLayout.java) -- it's not part of the Android SDK, so you have to copy the source code into your app in order to use it in your XML layouts.

You also need to add this to `res/values/attrs.xml`:

```
<declare-styleable name="ProportionalLayout">
    <attr name="direction" format="string"/>
    <attr name="ratio" format="float"/>
</declare-styleable>

```
I have faced with this question month ago. The found the only way to solve it:
In the layout file make width = match\_parent, and height = 0dp or whatever!

In the onCreate method add of your activity add onGlobalLayoutListener(). This method will be called when all heights and widths of all widgets are measured. So you can get your width by mLinearLayout.getWidth(); 

```
void onCreate(..) {
    ...
    mLinearLayout = getViewById(R.id.your_layout);          
    mFrameLayout.getViewTreeObserver().addOnGlobalLayoutListener(myOnGlobalLayoutListener);
}

OnGlobalLayoutListener myOnGlobalLayoutListener =new OnGlobalLayoutListener(){
    @Override
    public void onGlobalLayout() {
        if (!mFlag) {
            mFlag = true;
            mLinearLayout.setLayoutParams(mLinearLayout.getWidth(), mLinearLayout.getWidth() / 2));
        }
    }
};

```

Sorry for my english!
Hope it will help you!