2016-04-26 13 views
0

私はすべてのアンドロイドデバイスに同じ直径の2.5インチ(または他の値)の円を描画しようとしています。画面サイズ。直径の大きさはすべてのデバイスで同じでなければならず、以下は私が試したものです。Androidで同じ直径の異なる画面(デバイス)に円を描く方法

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)も使ってみましたが、うまくいきませんでした。

どのように私はすべての携帯電話で同じサイズの円の要件を達成することができますか?

+0

['DisplayMetrics'](http://developer.android.com/reference/android/util/DisplayMetrics.html)' xdpi'と 'ydpi'を使って、あなたの望む物理的なピクセルの正しい数を計算することができますサイズ。 –

+0

@ElliottFrisch: - 私にコード例を教えてもらえますか? – Barrier

+0

'dp'を試しましたか? – Max

答えて

-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> 

//このコードを使用すると、あなたは、通常では2.5インチのような

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. 

//、大規模で正常値の1.5倍 にdimens.xmlを置くことができます(およそ10mlの液体フッ化水素を圧入1.875in意味)小さなにXLARGEに(手段5インチ)、通常の .75xを正常値の、 2倍(3.75inを意味する)

//は、それはあなたのために参考になっかもしれ願っています。

+0

ダイメンはキャンバスの描画に使用できません! – GensaGames

+0

はい、キャンバスにはdimenを使用できます。 –

+0

あなたの答えでは、デバイスごとに異なるサイズを再び与えています。私はどこでも2.5インチが必要です。 – Barrier

関連する問題