Moni Moni - 1 year ago 100
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download