0

画面サイズに関係なく、すべての 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)も使ってみましたが、うまくいきませんでした。

では、すべての電話で同じサイズの円の要件をどのように達成できますか?

4

1 に答える 1

-1

//すべての画面に対して oval_shape.xml で固定の静的サイズを使用しています。そのため、画面ごとに異なります。これは次元で使用できます。// このコードを 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="@dimen/inch_size"
        android:height="@dimen/inch_size"/>
</shape>

// そして dimens.xml を入れることができます

1) values-xlarge

2) values-small

3) values-normal

4) values-large

And give different sizes in dimens.xml within corresponding folders according to densities.

// 通常の場合は 2.5 インチ、大の場合は通常の値の 1.5 倍 (3.75 インチを意味する)、大の場合は通常の値の 2 倍 (5 インチを意味する)、小の場合は通常の 0.75 倍 (約 1.875 インチを意味する)

//お役に立てば幸いです。

于 2016-04-26T06:11:45.687 に答える