无论屏幕大小如何,我都试图在每个Android设备中绘制一个直径为2.5英寸(或任何其他值)的圆圈 . 所有设备的直径尺寸必须相同,以下是我的尝试 .
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@drawable/light"
tools:context=".MainActivity">
<ImageView
android:layout_width="3in"
android:layout_height="3in"
android:src="@drawable/oval_shape"
android:id="@+id/imageView"
android:scaleType="matrix"/>
</RelativeLayout>
oval_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#666666"/>
<size
android:width="2.5in"
android:height="2.5in"/>
</shape>
这个代码的问题是当我在屏幕(真实手机)中使用4.5时,直径是2.5英寸,但是当在4英寸屏幕上测试直径小于2.5英寸时,它有一点点差异 . 我尝试使用毫米(mm),但它也不能很好地工作 .
那么如何在每部手机中达到相同尺寸圈的要求呢?
1 回答
//您正在使用oval_shape.xml中的修复静态大小来显示所有屏幕 . 这就是为什么不同屏幕的变化 . 你可以在尺寸中使用它 . //在oval_shape.xml中使用此代码
//你可以把dimens.xml放进去
//正常时为2.5in,正常值为1.5x(表示3.75in),xlarge中正常值的2x(表示为5in),小于正常值的0.75x(表示为aprox中的1.875)
//希望它对你有帮助 .