2012-02-23 2 views
1

Layout은 전화기에서 예상대로 표시되며 에뮬레이터에서 다르게 보입니다. SDK API 10 (Android 2.3)을 사용하고 있습니다. 테스트 폰은 Android 2.3.3 (Cyanogen Mod 7)이 장착 된 Motorola Milestone입니다.에뮬레이터와 휴대 전화에서 다르게 보이는 AppWidget

SDK 레이아웃 미리보기는 에뮬레이터와 같은 미리보기를 렌더링합니다.

다음 이미지는 예상되는 오른쪽 렌더링 (전화로 렌더링)과 예상치 못한 렌더링 (SDK API 10, 에뮬레이터 및 미리보기)을 보여줍니다.

shifted View

무엇의 차이에 대한 이유는 무엇이며 어떻게 해결합니까? 여백 및 패딩 제거 (0dp로 설정하여 TextView1) 도움이되지 않았습니다.

기본 레이아웃 (상위)

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/test_bg_red" 
     android:padding="20dp" 
> 

    <include 
     android:layout_width="fill_parent" 
     android:layout_height="26dp" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     layout="@layout/test_child" /> 
/> 

    <include 
     android:layout_width="fill_parent" 
     android:layout_height="26dp" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     layout="@layout/test_child" /> 

</RelativeLayout> 

하위 레이아웃 I이 상이한 종횡비를 갖는 다른 스크린에 의한 것으로 판단

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="26dp" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginRight="4dp" 
     android:gravity="top" 
     android:includeFontPadding="false" 
     android:text="42" 
     android:textSize="32dp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/textView1" 
     android:layout_toRightOf="@+id/textView1" 
     android:includeFontPadding="false" 
     android:text="TextView2" 
     android:textSize="12dp" /> 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/textView2" 
     android:layout_alignParentTop="true" 
     android:includeFontPadding="false" 
     android:text="TextView3" 
     android:textSize="10dp" /> 

</RelativeLayout> 

답변

1

. 휴대 전화는 물리적 인 화면 크기에 관계없이 4x4 셀을 사용하기 때문에 각 셀은 4 개를 연속으로 맞추기 위해 더 넓거나 좁아야합니다. DP를 사용하는 것은 밀도를 처리하지만, 다소 정사각형 인 스크린은 셀이 더 많거나 적은 사각형을 필요로합니다. 즉, 셀당 DP 수는 달라져서보기가 다른 장치에서 동일하게 보이지 않게됩니다.

내가 찾은 유일한 해결책은 레이아웃을 최대한 유연하게 만드는 것입니다.

관련 문제