2015-04-03 67 views
1

我想一个底部边框添加到我的TextView的,是这样的:Android的如何添加底部边框这样

enter image description here

你能帮助我这样做呢?我不想使用9patch png,是否可以通过使用xml drawable来实现?

+0

您是指顶部而不是底部? – pskink 2015-04-03 13:43:57

+0

@pskink,底部或顶部没有什么不同,我怎样才能将这个边框添加到我的视图? – 2015-04-03 13:51:42

+1

九块补丁是为了做这样的效果而设计的,尝试一下,我不知道你为什么不想要它们...... – pskink 2015-04-03 13:53:01

回答

0

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> 

希望这有助于:)

+0

你没有明白我的意思,我想添加边框而不是对齐视图 – 2015-04-03 13:51:05

1

您需要使用nine-patch添加这样的阴影,用一个附在这里

enter image description here

3

你可以使用图层列表:

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:左,右,..

把它用在文本视图则必须将其保存到资源/ drawable,然后将文本视图的背景设置为:

android:background:"@drawable/border" 
相关问题