侧面开放的Andr​​oid的行程? [英] Open-sided Android stroke?

查看:121
本文介绍了侧面开放的Andr​​oid的行程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在只有某些边创建一个Android形状对象中风?

Is it possible to create an Android shape object with stroke on only certain sides?

例如我有:

<stroke 
 android:width="3dip" 
 android:color="#000000"
    android:dashWidth="10dip" 
    android:dashGap="6dip" />

这是类似于此的CSS:

Which is similar to this CSS:

border: 3px dashed black;

如何设置上只是一个侧面中风?这是我会怎么做,在CSS:

How can I set the stroke on just one side? This is how I would do it in CSS:

border-left: 3px dashed black;

你是怎么做到这在Android中的XML?

How do you do this in Android XML?

推荐答案

我实现了这一个很好的解决方案:

I achieved a good solution with this one:

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the line -->
    <item android:top="-1dp" android:right="-1dp" android:left="-1dp">
      <shape>
            <solid android:color="@android:color/transparent" />
            <stroke android:width="1dp" android:color="#ffffff" />
      </shape>
    </item>

</layer-list>

这可以很好的情况下,你需要一个透明的颜色,但仍然是一个开放的笔触颜色(在我来说,我只需要一个底线)。如果你需要一个背景颜色,你可以添加一个坚实的形状颜色如上回答。

This works well in case you need a transparent color but still an open stroke color (In my case i only needed a bottom line). If you need a background color you can add a solid shape color as in above answer.

*修改

有时候,对于高密度设备,使用低倾角最终可能非常薄的或无形的笔或距离。这可能发生在你设置的ListView分频器也当。

Sometimes, for High Density devices, using low dips may end in very thin or invisible strokes or distances. This may happen to you also when setting ListView dividers.

最简单的解决方法是使用1px的,而不是1DP的距离。这将使该行总是在所有的密度可见。 最好的解决办法是创建维度的资源为每个密度,让每个设备的最佳尺寸。

The simplest workaround is to use a distance of 1px instead of 1dp. This will make the line always visible at all densities. The best solution would be to create dimension resources for each density, to get the best size for each device.

这篇关于侧面开放的Andr​​oid的行程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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