我的10dp高度按钮在哪里? [英] Where did my 10dp height button goes?

查看:84
本文介绍了我的10dp高度按钮在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为3台设备进行了如下编码(下图),并记录了密度/分辨率/操作系统(以便您知道哪台设备是哪台).我有5个按钮和5个图像,每个按钮的高度从10dp到50dp.

I have coded as below for 3 devices (images below), and log the Density/Resolution/OS (so that you know which device is which). I have 5 buttons and 5 images, each with height from 10dp to 50dp.

您会注意到图像出现在所有设备上.所有按钮都显示在XXXHDPI设备(这是三星S7设备)上,但是在XXHDPI(Nexus 5)和XHDPI(三星S3)上,10dp按钮消失了.为什么?

You'll notice the images appears on all devices. All the buttons appear on on XXXHDPI device (which is a Samsung S7 device), but for on XXHDPI (Nexus 5) and XHDPI (Samsung S3), the 10dp button disappeared. Why?

以下图像

我的布局如下(没有其他特殊代码,只有默认的Empty Activity项目).

And my layout as below (no other special code, just the default Empty Activity project).

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.elyeproj.phoneinfo.MainActivity">

    <TextView
        android:id="@+id/resolution_width"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/resolution_height"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/resolution_width_dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/resolution_height_dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/resolution_density"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/resolution_density_str"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/phone_os"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="10dp" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="20dp" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="30dp" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="40dp" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="50dp" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:layout_marginBottom="5dp"
        android:background="@android:color/holo_blue_dark"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:layout_marginBottom="5dp"
        android:background="@android:color/holo_blue_dark"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_marginBottom="5dp"
        android:background="@android:color/holo_blue_dark"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginBottom="5dp"
        android:background="@android:color/holo_blue_dark"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@android:color/holo_blue_dark"/>
</LinearLayout>

推荐答案

问题"位于默认按钮背景及其内部填充中. 要解决-为按钮背景设置一些颜色

the "problem" is in default button background and its internal paddings. To fix - set some color to buttons background

例如

android:background="@android:color/holo_red_dark"

这篇关于我的10dp高度按钮在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆