i have a RelativeLayout
here's the code :
<RelativeLayout
android:id="@+id/camerapreview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:background="#000">
</RelativeLayout>
its a camera preview for the camera application, i set the width
to match_parent
.
and here is my java code :
RelativeLayout preview = (RelativeLayout) findViewById(R.id.camerapreview);
int w = preview.getWidth();
LayoutParams params = preview.getLayoutParams();
params.width = w;
params.height = w;
preview.addView(mPreview);
basically i decalaired the width of the RelativeLayout
to match_parent
to be dynamic to the width of any device. But i want the view to be square so i used the java code
abave, but every time i ran the program this line int w = preview.getWidth();
returns zero. I must have missed something, help please :D thank you.