Moni Moni - 1 month ago 8
Android Question

Android view same height as width the width is dynamic

Now how to tell for the

SurfaceView
to be square, have the same height as
ImageView
's width?

<RelativeLayout
android:id="@+id/rlQr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_below="@+id/rlTop">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ivScanTop"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:background="@drawable/qr_margin_top" />

<SurfaceView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_alignLeft="@+id/ivScanTop"
android:layout_alignRight="@+id/ivScanTop"/>

Answer

Based on this answer you should extend the SurfaceView and add that one on the .xml file. In that case the UI designer will show a square.