【问题标题】:How to border only left, top and bottom for TextViewTextView 如何仅在左侧、顶部和底部设置边框
【发布时间】:2017-01-01 00:19:18
【问题描述】:

这是我的编码。这是 TextView 4 边框的设计蓝色。我想要的是只设计 3 个边框(顶部、左侧和底部)。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape>
            <solid
                android:color="#449def" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="0dp" />
            <padding
                android:left="5dp"
                android:top="5dp"
                android:right="5dp"
                android:bottom="5dp" />
        </shape>
    </item>
    <item>
        <shape>
            <gradient
                android:startColor="#ffffff"
                android:endColor="#ffffff"
                android:angle="270" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="0dp" />
            <padding
                android:left="5dp"
                android:top="5dp"
                android:right="5dp"
                android:bottom="5dp" />
        </shape>
    </item>
</selector>

【问题讨论】:

标签: android


【解决方案1】:

下面的代码放在1dp高度的底部,你必须在其他方面玩这个

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<!-- This is the line -->
<item>
  <shape>
        <solid android:color="#535353" />
  </shape>
</item>

<!-- This is the main color -->
<item android:bottom="1dp">
 <shape>
       <solid android:color="#252525" />
 </shape>
</item>
</layer-list>

参考这个讨论Open-sided Android stroke?

【讨论】:

  • 您提供的链接中的行和主颜色不同,我认为您的链接是错误的。评论应该改变
【解决方案2】:

这是一个快速的解决方案(可能是愚蠢的),在您的TextView 上添加android:translationX="2dp",您可以添加android:paddingRight="2dp" 以弥补丢失的空间。

【讨论】:

    【解决方案3】:

    这样试试

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape>
                <padding android:bottom="1dp" android:left="1dp" android:right="0dp"
                    android:top="1dp"/>
                <solid android:color="#000"/>
            </shape>
        </item>
    
        <!-- Background -->
        <item>
            <shape>
                <solid android:color="@color/white"/>
    
            </shape>
        </item>
    </layer-list>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-24
      • 1970-01-01
      • 1970-01-01
      • 2020-01-29
      • 1970-01-01
      • 1970-01-01
      • 2021-06-14
      相关资源
      最近更新 更多