Android 不同屏幕尺寸的相对布局问题
Android RelativeLayout Issue with different screen dimentions
<?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>
输出:
这个例子可以帮到你。
<?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"
>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
</RelativeLayout>
</LinearLayout>
<?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>
输出:
这个例子可以帮到你。
<?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"
>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
</RelativeLayout>
</LinearLayout>