私のクライアントは、別のツールを持ち歩くことなく特定のものを測定できるように、アプリ内にビルトインのルーラーが必要です。定規をレイアウトするときを単位で使用すると、ほとんどのテストデバイスで問題なく動作します。一部のデバイスは、インチ単位で不正確に表示されますので、そのDPは、にの代わりに使用されなければならないのにAndroidのメーカーは私を警告します。 Amazon Fire 7インチタブレットでテストすると、ハッシュマークの間隔が広すぎます。私の理解では、160dpは常に1インチに等しくなければならないので、私はそれぞれ1インチと2インチのハッシュマークに対して160dpと320dpに切り替えようとします。今回は、ハッシュマークがあまりにも近くにあります。下のスクリーンショットを参照してください。黒いマークはインチを使用しています。赤いマークはdpを使用しています。正しいサイズはとの間にあり、黒と赤のマークです。一部のタブレットでインチ/ dp値が正しくありません
すべてのデバイスで正しいインチ値を指定または変換するにはどうすればよいですか?私はXMLですべての値を指定する方が好きですが、Javaコードを使用して必要に応じてレイアウトを調整してください。また、あるデバイスでインチ単位が正しいかどうかを調べるためのプログラム的な方法はありますか?
ありがとうございました。ここで
は私のコードです:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/one_inch_left"
android:layout_width="@dimen/ruler_hash_width"
android:layout_height="1px"
android:layout_marginTop="1in"
android:background="@color/solid_black"
app:layout_constraintTop_toBottomOf="parent"/>
<View
android:id="@+id/two_inch_left"
android:layout_width="@dimen/ruler_hash_width"
android:layout_height="1px"
android:layout_marginTop="2in"
android:background="@color/solid_black"
app:layout_constraintTop_toBottomOf="parent"/>
<View
android:id="@+id/one_inch_left2"
android:layout_width="@dimen/ruler_hash_width"
android:layout_height="1px"
android:layout_marginTop="160dp"
android:background="@color/red_button_color"
app:layout_constraintTop_toBottomOf="parent"/>
<View
android:id="@+id/two_inch_left2"
android:layout_width="@dimen/ruler_hash_width"
android:layout_height="1px"
android:layout_marginTop="320dp"
android:background="@color/red_button_color"
app:layout_constraintTop_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>