Reputation:
Like in title. Layout looks great on Android Studio, but when I get it on real device it looks bad. The JavaCameraView takes only half of the screen while in Android Studio takes about 3/4 as it should be. JavaCameraView should reach horizontal bar shown on screen.
Here are my screenshots.
On Android Studio:
On real device:
Layout Inspector shows that this RelativeLayout that hosts JavaCameraView occupies all that space but JavaCameraView with height:match_parent not behaves like that:
Why is that so?
Here is my layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:layout_above="@+id/scroll_view">
<org.opencv.android.JavaCameraView
android:id="@+id/java_surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
opencv:camera_id="any"
opencv:show_fps="true" />
</RelativeLayout>
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="?actionBarSize">
<RelativeLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/View1"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/alert_pxcm_too_small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/View1"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textColor="#FF0000"
android:textSize="@dimen/text_size_rest"
android:visibility="visible" />
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_below="@id/alert_pxcm_too_small"/>
<TextView
android:id="@+id/measurements_width_converter"
android:layout_marginTop="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/spinner"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textColor="#0000FF"
android:text="@string/width_info"
android:textSize="@dimen/text_size_rest"
android:visibility="visible" />
<TextView
android:id="@+id/measurements_height_converter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/measurements_width_converter"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textColor="#0000FF"
android:text="@string/width_info"
android:textSize="@dimen/text_size_rest"
android:visibility="visible" />
</RelativeLayout>
</ScrollView>
If you need something more just ask. Probably you will need also some Java code of classes, this fragment etc. Thank you in advance! :)
Upvotes: 0
Views: 105
Reputation:
Here is the working correctly layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginBottom="?actionBarSize">
<org.opencv.android.JavaCameraView
android:id="@+id/java_surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/scroll_view"
android:layout_alignParentTop="true"
opencv:camera_id="any"
opencv:show_fps="true" />
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="150dp">
<View
android:id="@+id/View1"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/alert_pxcm_too_small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/View1"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textColor="#FF0000"
android:textSize="@dimen/text_size_rest"
android:visibility="visible" />
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/alert_pxcm_too_small"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" />
<TextView
android:id="@+id/measurements_width_converter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/spinner"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:gravity="center_horizontal"
android:text="@string/width_info"
android:textColor="#0000FF"
android:textSize="@dimen/text_size_rest"
android:visibility="visible" />
<TextView
android:id="@+id/measurements_height_converter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/measurements_width_converter"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:text="@string/width_info"
android:textColor="#0000FF"
android:textSize="@dimen/text_size_rest"
android:visibility="visible" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Upvotes: 0
Reputation: 2981
Your problem is on the value you're using in android:layout_weight
and how you're set the android:layout_width
and android:layout_height
.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.3"
..
>
<org.opencv.android.JavaCameraView
android:layout_width="match_parent"
android:layout_height="match_parent"
..
/>
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.7"
<!-- Other views here -->
</ScrollView>
</LinearLayout>
Upvotes: 1