android - 孩子的Android match_parent没有达到父母的体重
问题描述
就像标题一样。布局在 Android Studio 上看起来很棒,但是当我在真实设备上得到它时,它看起来很糟糕。JavaCameraView 只占屏幕的一半,而在 Android Studio 中,它应该占大约 3/4。JavaCameraView 应该达到屏幕上显示的水平条。
这是我的截图。
在 Android Studio 上:
在真实设备上:
Layout Inspector 显示托管 JavaCameraView 的这个 RelativeLayout 占据了所有空间,但具有 height:match_parent 的 JavaCameraView 的行为不是这样:
为什么呢?
这是我的布局:
<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>
如果您需要更多内容,请询问。可能您还需要一些 Java 类代码、此片段等。提前谢谢您!:)
解决方案
您的问题在于您使用的值android:layout_weight
以及如何设置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>
推荐阅读
- javascript - Discord.js ReactionCollector 帮助菜单 - 重置表情符号
- wordpress - Wordpress HTTP 请求 501 内部服务器错误
- java - 如何成功遍历预填充的 ArrayList 以找到每个连续元素的差异并将其打印出来?
- vue.js - Electron-vue 创建新窗口
- python-3.x - 在 Windows 10 上带有上下文管理器的 Python 临时文件导致 PermissionError:[Errno 13]
- angular - 如何构建结合了 Angular 和 Spring Boot 应用程序的 Docker 映像?
- php - 使用 PHP 更新 sql 表中的字段
- javascript - JS:实例化变量无法识别输入值
- xaml - 非根对象中的 XAML 事件处理程序
- java - Axon - MySql 的 JPA 事件存储