android - 不同屏幕尺寸的Android RelativeLayout问题
问题描述
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.testing.testinglibraryapps.Main2Activity">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RelativeLayout>
</RelativeLayout>
如何将 Android 屏幕分为两部分。即一个相对布局应该在屏幕的 3/4 部分,另一个应该是 1/4
我应该在这里设置什么属性来实现我想要的布局
解决方案
你可以这样做
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:weightSum="4"
xmlns:android="http://schemas.android.com/apk/res/android"
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="3"
android:background="@android:color/holo_green_dark"
>
<!--Other Views Here-->
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/holo_red_dark"
>
<!--Other Views Here-->
</RelativeLayout>
</LinearLayout>
输出:
推荐阅读
- c++ - Cppcheck“引用自动变量返回”失败的原因?
- spring-boot - Swagger-UI 在根端点上不显示 SpringBoot 和路径参数
- android - Android:在 ListView 中获取数据
- code-coverage - 将 codecov 补丁目标设置为固定数字
- java - 使用 PDFBox - Java 在 AWS S3 位置保存 pdf
- ios - iOS:在文本 UILabel 周围绘制边框
- c# - MVC 和 AJAX 调用失败
- c# - 通过 C# 中的 putty 从文件执行命令
- c - 如何在 AC_COMPILE_IFELSE 程序中使用 AC_CHECK_HEADER 标头
- python - 导入/导出 .csv 列表