开发者

Is it true that when coding for android 360dp = the whole screen width?

It seems like that for me, on my virtual android de开发者_如何转开发vice.

If this isn't the case, then how can I specify eg. 35% of the screen width, without using 360*.35 = 126dp?


Is it true that when coding for android 360dp = the whole screen width?

No.

It seems like that for me, on my virtual android device.

It is not "the whole screen width" for any standard Android screen resolution that I can think of. For example, 360dp = 360px for medium density screens and 540px for high-density screens, and I know of precisely zero Android devices with 360px or 540px in either dimension.

Also, bear in mind that "the whole screen width" will vary depending upon whether the device is in portrait or landscape mode.

If this isn't the case, then how can I specify eg. 35% of the screen width, without using 360*.35 = 126dp?

Use a LinearLayout and android:layout_weight. Here is a sample project demonstrating this. The key is in the layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button
        android:text="Fifty Percent"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="50"
    />
    <Button
        android:text="Thirty Percent"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="30"
    />
    <Button
        android:text="Twenty Percent"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="20"
    />
</LinearLayout>

Each widget is denoted as having no intrinsic height, so the total height is divided up among the widgets based on their relative weights.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜