سؤال

The Layout is looking as expected on the phone and looking different on the emulator. I am using SDK API 10 (Android 2.3). The test phone is a Motorola Milestone with Android 2.3.3 (Cyanogen Mod 7).

The SDK layout preview renders the preview like the Emulator.

The following image shows the expected rendering on the right side (rendered by phone) and the unexpected rendering on the left side (SDK API 10, emulator and preview).

shifted View

What is the reason for the difference and how do I fix it? Removing margin and padding (by setting it to 0dp at TextView1) did not help.

main layout (parent)

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

child layout

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

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top