android - 为 android 编码时 360dp = 整个屏幕宽度是真的吗?

标签 android

在我的虚拟 android 设备上,对我来说似乎是这样。

如果不是这种情况,那么我该如何指定,例如。屏幕宽度的 35%,不使用 360*.35 = 126dp?

最佳答案

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

没有。

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

它不是我能想到的任何标准 Android 屏幕分辨率的“整个屏幕宽度”。例如,360dp = 360px 用于中密度屏幕,540px 用于高密度屏幕,我知道恰好有零个 Android 设备在任一维度上都为 360px 或 540px。

另外,请记住,“整个屏幕宽度”会根据设备处于纵向模式还是横向模式而有所不同。

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

使用 LinearLayoutandroid:layout_weightHere is a sample project证明这一点。关键在于布局:

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

每个小部件都表示没有固有高度,因此总高度根据它们的相对权重在小部件之间分配。

关于android - 为 android 编码时 360dp = 整个屏幕宽度是真的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5445659/

相关文章:

java - 在 Java 中处理延迟事件的最佳方法是什么

java - 在 Android 中将 Php 连接到 MySQLi

android - 如何将 onBackButton 监听器设置为 Activity

java.lang.IllegalStateException : Could not execute method for android:onClick/Android 错误

Android fragment 和 ViewPager : Crash When Orientation Change

java - 我怎样才能使 URLEncoding 不编码冒号?

java - 如何将 JSONArray 转换为通用 List<T>?

java - alertdialog - removeView 必须被调用

javascript - 移动 safari 或 chrome 上的屏幕键盘打开时是否会触发任何 javascript 事件?

android - 跨越 2 个 fragment 的按钮(xml 布局)