简体   繁体   English

Nexus 7平板电脑上的填充问题

[英]Padding issue on Nexus 7 tablet

I'm noticing some issues with padding on the Nexus 7 tablet running Android 4.1. 我注意到在运行Android 4.1的Nexus 7平板电脑上有一些填充问题。 Specifically, I have a background drawable with padding that creates a outer stroke: 具体来说,我有一个背景绘制填充,创建一个外部笔划:

  <?xml version="1.0" encoding="utf-8"?>
  <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >

  <stroke
    android:width="1dp"
    android:color="#59000000" />

  <padding
    android:bottom="1dp"
    android:left="1dp"
    android:right="1dp"
    android:top="1dp" />

  </shape>

This is supplemented with a 1dp white inner stroke. 这补充了1dp白色内部笔画。 So it should be a square 2 dp border around the entire image: 所以它应该是整个图像周围的正方形2 dp边框:

I have tested it on the actual nexus device and on several other devices and the 7 inch jelly bean emulator: 我已经在实际的nexus设备和其他几个设备以及7英寸果冻豆模拟器上进行了测试:

First, here is the working version from the 4.1 7 inch emulator: 首先,这是4.1 7英寸仿真器的工作版本: 这是用于4.1的7英寸平板电脑模拟器

The border around the outside is even and goes around the entire image. 外围的边界是均匀的,并围绕整个图像。 This is how it works on all the other devices i have as well. 这就是它在我拥有的所有其他设备上的工作方式。

Nexus 7: Nexus 7:

图像与搞砸填充

The gray is the background color, but you can see the right and bottom padding is not being respected. 灰色是背景颜色,但您可以看到右侧和底部填充没有得到遵守。 The border is being obscured by the the image now. 现在,图像遮挡了边界。

If it matters, these are children of a GridView. 如果重要,那么这些是GridView的子代。 Wonder if anyone has seen these issues or has ideas on how to resolve them. 不知道是否有人看过这些问题或有关于如何解决这些问题的想法。

This appears to be a bug when generating the stroke in the XML drawable. 在XML drawable中生成stroke时,这似乎是一个错误。 After multiple attempts, I've narrowed it down to that; 经过多次尝试,我把它缩小到了那个; it seems to be making the stroke size incorrectly on the lower and right sides of the shape, even if specified in pixels. 它似乎是在形状的下侧和右侧错误地使笔划大小,即使以像素为单位指定。 If I simply change the stroke width to 2dip instead of 1dip (all other things staying as they are), this is the result: 如果我只是将笔划宽度更改为2dip而不是1dip (所有其他内容保持1dip ),结果如下:

在此输入图像描述

This is the border.xml I used for the background of the after image: 这是我用于后映像背景的border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

    <stroke
            android:width="2dp"
            android:color="#59000000"/>

    <padding
            android:bottom="1dp"
            android:left="1dp"
            android:right="1dp"
            android:top="1dp"/>

</shape>

Which, again, is just yours with the stroke width enlarged. 再次,这是你的笔画宽度放大。 The good thing is, this won't change the expected result at all since the padding remains the same. 好处是, 这不会改变预期的结果,因为填充保持不变。 In fact, you can change the stroke tag to solid and still have the same result (however, if your images contain transparency you'd see the solid background in the transparent areas). 实际上,您可以将stroke标记更改为solid并且仍然具有相同的结果(但是,如果图像包含透明度,则会在透明区域中看到纯色背景)。

Give this a try; 试一试; let me know how it works for you! 让我知道它对你有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM