0

Is there anyway in Android to set the height of the LinearLayout to match it's width?

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="MATCH_WIDTH_OF_THIS_LinearLayout"

I have the LinearLayout to match_parent's width, and I want this LinearLayout to match it's own width for it's height.

Onik
  • 19,396
  • 14
  • 68
  • 91

3 Answers3

0

Yes there is, by using

android:adjustViewBounds(true);
  • Can't see this parameter in [LinearLayout.LayoutParams](https://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html) – Onik Sep 19 '16 at 01:38
0

set width in java code before the content has been layout,such as onCreate.

Tom.Chen
  • 1
  • 2
0

Use myLayout.getWidth() to get the width of the LinearLayout and set its height to that value. You'll need to do that in onCreate.

Android: get width of Layout programatically having fill_parent in its xml

Android: How to Programmatically set the size of a Layout

Community
  • 1
  • 1
Lokesh Saini
  • 106
  • 1
  • 6