【问题标题】:android-How to add bottom border like thisandroid-如何像这样添加底部边框
【发布时间】:2015-04-03 13:40:47
【问题描述】:

我想为我的 textView 添加一个底部边框,如下所示:

你能帮我这样做吗?我不想使用 9patch png ,是否可以通过使用 xml drawable 来做到这一点?

【问题讨论】:

  • 你的意思是顶部,而不是底部?
  • @pskink,bottom 或 top 没有区别,如何将这个边框添加到我的视图中?
  • 设计了九个补丁来做这样的效果,试试吧,我不知道你为什么不想要它们......

标签: android textview android-styles


【解决方案1】:

你可以使用层列表来做到这一点:

border.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid android:color="@color/WhiteSmoke"/>
        <corners android:radius="2dp" />
    </shape>
</item>

<item
    android:left="2dp"
    android:right="2dp"
    android:top="5dp"
    android:bottom="0dp">
    <shape android:shape="rectangle">
        <solid android:color="@android:color/white"/>
        <corners android:radius="2dp" />
    </shape>
</item>

你可以在哪里定义边框的粗细在android:left,right,..

要在文本视图上使用它,您必须将其保存到 res/drawable 中,然后将文本视图的背景设置为:

android:background:"@drawable/border"

【讨论】:

    【解决方案2】:

    你需要使用nine-patch来添加这样的阴影,使用这里所附的

    【讨论】:

      【解决方案3】:

      android:layout_alignParentBottom 属性必须在 RelativeLayout 的元素中声明。

      这里是示例代码 -

      <RelativeLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"         
       android:layout_centerHorizontal="true">
        <ListView ...>
        <Button android:id="@+id/btnGetMoreResults"
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content"     
         android:text="Get more"
         android:layout_alignParentBottom="true" />
      </RelativeLayout>
      

      希望这有帮助:)

      【讨论】:

      • 你没明白我的意思,我想添加边框不对齐视图
      猜你喜欢
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      • 2015-11-10
      • 2020-10-24
      • 1970-01-01
      • 2015-04-21
      • 2019-02-08
      • 1970-01-01
      相关资源
      最近更新 更多