title: Widget aspect ratio 1:1 (square)
body: <p>I need to make widget aspect ratio 1:1 - more precisely it has to be square.</p>
  
  <p>My layout looks like this:</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;ImageView
      android:id="@+id/backgroundImage"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:clickable="false"
      android:focusable="false"
      android:scaleType="fitXY"
      android:src="@drawable/rounded_conners" /&gt;
  
  &lt;ImageButton
      android:id="@+id/button"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_gravity="center"
      android:adjustViewBounds="true"
      android:background="@drawable/transparent_color"
      android:clickable="true"
      android:focusable="true"
      android:padding="8dp"
      android:scaleType="fitCenter"
      android:src="@drawable/btn03_off" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>I'm changing the shape of the ImageView programmatically so it has to be ImageView. In the background is shape background and on the top of that is ImageButton.</p>
  
  <p>I was trying to make my own SquareLayout extended from LinearLayout, but it seems that Android widget shows only LinearLayout and not his extended version where I overridden onMeasure(meethod)</p>
  
  <pre><code>public class SqueareLinearLayout extends LinearLayout {
  public SqueareLinearLayout(Context context) {
      super(context);
  }
  
  public SqueareLinearLayout(Context context, AttributeSet attrs) {
      super(context, attrs);
  }
  
  
  @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      super.onMeasure(widthMeasureSpec, widthMeasureSpec);
      int width = MeasureSpec.getSize(widthMeasureSpec);
      int height = MeasureSpec.getSize(heightMeasureSpec);
      int size = width &gt; height ? height : width;
      setMeasuredDimension(size, size);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Does anybody know how to do that?</p>