2017-09-17 10 views
-2

dpの定義には、密度に関係なく同じ寸法のデバイスで10dpが同じである必要があります。それで、Android Studioのレイアウトプレビューが、モバイルで実行しているときにレイアウトと一致しないのはなぜですか?私はAndroid StudioのプレビューでピクセルXLを使用しています、私はサムスンJ7プライムでそれを実行しています。ともに5.5" は斜めが異なるdensities.Layoutコードで: - それはあなたにこのエラーを示しIDEの問題があるAndroidのレイアウトのプレビューがデバイスと一致しない

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/re/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/ll" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center_vertical|center_horizontal|center" 
    tools:layout_editor_absoluteY="25dp" 
    tools:layout_editor_absoluteX="0dp"> 


<ProgressBar 
    android:id="@+id/progressBar2" 
    style="?android:attr/progressBarStyle" 
    android:layout_width="147dp" 
    android:layout_height="173dp" 
    app:layout_constraintTop_toTopOf="parent" 
    android:layout_marginTop="454dp" 
    android:layout_marginStart="248dp" 
    app:layout_constraintLeft_toLeftOf="parent" 
    android:layout_marginEnd="16dp" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintHorizontal_bias="0.0" /> 

<SeekBar 
    android:id="@+id/seekBar" 
    android:layout_width="122dp" 
    android:layout_height="116dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:background="@android:color/black" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toLeftOf="@+id/progressBar2" 
    app:layout_constraintTop_toTopOf="parent" 
    android:layout_marginTop="494dp" 
    app:layout_constraintHorizontal_bias="0.518" /> 

<RatingBar 
    android:id="@+id/ratingBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="9dp" 
    android:layout_marginStart="16dp" 
    android:layout_marginTop="8dp" 
    android:background="@android:color/holo_purple" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    app:layout_constraintVertical_bias="0.75" /> 

</android.support.constraint.ConstraintLayout> 

The screenshot of the app:

Here is the picture of preview:

+0

ウィジェットが重複していない動作すること、ビュー間のより良い関係を作成します。 –

+0

今後削除される可能性のあるリンクではなく、スクリーンショットをウェブサイトに配置してください。 –

+0

これを行うにはもっと星/バッジが必要です –

答えて

0

、あなたは何をすべきか、あなたは毎回です使用するウィジェットは、常に幅をwrap_contentまたはmatch_parentとしてください。あなたの取得方法が自然の電話とは少し違うプレビューです。

身長については身長を教えてください。画面の幅が問題となります。

問題のサイズがwrap_contentにある場合は、希望の結果を得るためにこのようにすることができます。

<ProgressBar 
    android:width="match_parent" 
    android:height="115dp" 
    android:marginLeft="20dp" 
    androidMarginRight="20dp"> 

は、あなたは他のマージン何の値を調整することができ、所望の幅を達成することができます。

このようなことをする利点は、電話機(Real One)の全領域を占有し、それに応じてマージンを調整するため、電話機で望ましい結果を得ることです。

試してみて、結果が得られているかどうかを教えてください。

EDITS

あなたの問題のために、次のように行います

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_marginTop="25dp" 
     android:layout_weight="1"> 

     <RelativeLayout 
      android:layout_width="170dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_weight="1" 
      android:layout_marginRight="20dp"> 
      <Button 
       android:id="@+id/facebookButton" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:paddingTop="13dp" 
       android:paddingBottom="11dp" 
       android:layout_marginTop="4dp" /> 
     </RelativeLayout> 


     <RelativeLayout 
      android:layout_width="170dp" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="10dp" 
      android:layout_weight="1"> 
      <Button 
       android:id="@+id/googleButton" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"/> 
     </RelativeLayout> 
    </LinearLayout> 

を調整するために、あなたのレイアウトでは、次のように行います。

+0

高さはスクロールビューを使用できますが、幅が問題です。実際のレイアウトは非常に複雑で、ウィジェットは秩序のあるファッションなしでもばかげて配置されています。 –

+0

あなたは何を言っているのか分かりませんが、非常に率直なユーザー** match_parent **を幅として使用し、マージンを調整しても問題はありません。それを試してみてください。 –

+0

2つのウィジェットが並んでいて、その間に小さな隙間がある場合、マッチする親をどのように幅として使用できますか? –

0

ビューの位置付けにはパーセントを使用していますが、それらの通常のサイズ(wrap_contentまたは使用した固定サイズ)は、異なるデバイス表示で結果が異なることになります。

場合によっては重複し、一部では重複しません。

これを確認するには、複数のディスプレイで実行することをお勧めします。向きを変えて、さまざまなエミュレータ設定を試してみてください。

は、この問題を解決するために、複数のソリューションがあり、ニーズに応じて異なります。

  1. サイズと位置が一致している必要があります。どちらかの両方がパーセントであるか、あるいは両方が固定サイズです。

  2. 常にそれがあるべきよう

+0

ここでパーセンテージを使用しましたか? –

+0

たとえば、「layout_constraintHorizo​​ntal_bias」および「layout_constraintVertical_bias」という属性を使用しました。 –

+0

デバイスの同じ構成を表示するには、プレビューを試してください。私はあなたのデバイスと同じ結果を得ると信じています。 –

関連する問題