【发布时间】:2020-12-16 14:42:23
【问题描述】:
当我尝试将 svg 图像作为矢量添加到我的布局文件时,我遇到了屏幕兼容性问题。我的代码在下面
<androidx.constraintlayout.widget.ConstraintLayout
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=".ui.auth.AuthActivity">
<RelativeLayout
android:id="@+id/otNum"
android:background="@color/white"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:orientation="vertical">
<LinearLayout
android:paddingTop="50dp"
android:id="@+id/otpIcon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
>
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ic_otp_image"/> <-- ic_otp_image.xml in drawable -->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:layout_below="@id/otpIcon"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="50dp">
<!-- Some form content goes here-->
</LinearLayout>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
我正在使用 xxhdpi 的设备(即直接设备)上进行开发。上述布局设置在此设备上运行良好,但是当我在模拟器(hdpi 480 x 800)上进行设备兼容性测试时。图像占据了设备屏幕大小的一半以上,我所有的表单内容都超出了屏幕。我检查了不同的帖子,但找不到此问题的正确解决方案。
hdpi(left) 和 (xhdpi) 模拟器的屏幕截图:
【问题讨论】:
标签: android xml android-layout svg