I have a layout with graphics drawn in custom Views using the Canvas drawing primitives, plus a TextView and 2 buttons. The emulator is set to the same pixel width as the phone (400 pixels) and the 2D graphics are specified in pixel dimensions.
(Emulator on the left, phone on the right.)Note the the graphics match. (the actual content of the graphics are different because the data is different ) But the TextView and buttons are radically different. Here's the XML -
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:background="#303080"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/eventSummary"
android:layout_width="250dp"
android:background="#202090"
android:layout_height="fill_parent"
android:minLines="4"
android:singleLine="false"
android:text="text" />
<Button android:id="@+id/PrevButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="prevButtonHandler"
android:text="<"
/>
<Button android:id="@+id/NextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="nextButtonHandler"
android:text=">"
/>
</LinearLayout>
... I've tried specifying the TextView width using SP's and DP's. 开发者_开发问答Why is there such a big difference and how can I get the Emulator and phone to match? (FWIW the phone is an HTC Droid Incredible).
Thanks in advance!
Try setting the layout_width
in dp
in the LinearLayout
, then using android:layout_weight="1"
in the TextView
.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:background="#303080"
android:layout_width="280dp"
android:layout_height="wrap_content">
<TextView android:id="@+id/eventSummary"
android:layout_width="wrap_content"
android:background="#202090"
android:layout_height="fill_parent"
android:layout_weight="1"
android:minLines="4"
android:singleLine="false"
android:text="text" />
<Button android:id="@+id/PrevButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="prevButtonHandler"
android:text="<"
/>
<Button android:id="@+id/NextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="nextButtonHandler"
android:text=">"
/>
</LinearLayout>
I'm late, but its probably because of pixel density. Check out this link and see if it helps: http://developer.android.com/guide/practices/screens_support.html
精彩评论