Androidでチャートアプリケーションを開発しています。すべてのレイアウト パラメータを dp に設定しましたが、さまざまな画面サイズでの配置に関する問題に直面しています。
たとえば、通常の 4 インチ画面と比較して、ログイン ボタンまたはチャートが大きな画面サイズで表示されます。
これは OS バージョンのバグですか、それとも画面サイズの種類ごとにパラメータを設定する必要がありますか。
2 つの異なるモバイルでの同じログイン画面のスクリーンショット
この種の問題を回避するには、ボタン、テキスト フィールドなどを画面の余白に合わせます。
// for aligning it to the left of screen
android:layout_alignParentLeft="true"
// for aligning it to the right of screen
android:layout_alignParentRight="true"
// for aligning it to the Bottom of screen
android:layout_alignParentBottom="true"
その後、ウィジェットは画面の下、右、または左にそれぞれ元の場所を変更しません
答えを投票することを忘れないでください:)
相対レイアウトをメイン レイアウトとして使用します。その中に LinearLayout レイアウトを 1 つ追加します。これは、ログイン ボックスのコンテナーです。android:layout_centerInParent="true" を使用して配置を中央に設定します。このコンテナ内にログイン ボックスを追加します。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout >