Android——具有边框的Textview


我们可以看见很多类似瀑布流的分类:

通过边框进行选择,那么这个边框是怎么变成的呢? 我们可以通过添加背景图,不过有更加简单的,如下:

我们在drawable文件中编写一个shape,

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#fc1f65"/>
</shape>

最后在xml布局文件中bg中加入:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_margin="5dp"
android:background="@drawable/textview_border"
android:text="程序员"
android:gravity="center"
android:textColor="@color/text_color" />

<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_margin="5dp"
android:background="@drawable/textview_border"
android:text="工程师"
android:gravity="center"
android:textColor="@color/text_color" />
</LinearLayout>

怎么样还不错吧!我们还可以进行拓展比如边框的角变得圆润点,或是颜色修改,或者点击之后改变颜色!


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM