zoukankan      html  css  js  c++  java
  • Android随笔

    实现效果图:

    代码实现:

    Step 1:编写矩形边框的Drawable:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <!-- 设置一个黑色边框 -->
        <stroke android:width="2px" android:color="#000000"/>
        <!-- 渐变 -->
        <gradient
            android:angle="270"
            android:endColor="#C0C0C0"
            android:startColor="#FCD209" />
        <!-- 设置一下边距,让空间大一点 -->
        <padding
            android:left="5dp"
            android:top="5dp"
            android:right="5dp"
            android:bottom="5dp"/>
    
    </shape>

    Step 2:编写圆角矩形边框的Drawable:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    
        <!-- 设置透明背景色 -->
        <solid android:color="#87CEEB" />
    
        <!-- 设置一个黑色边框 -->
        <stroke
            android:width="2px"
            android:color="#000000" />
        <!-- 设置四个圆角的半径 -->
        <corners
            android:bottomLeftRadius="10px"
            android:bottomRightRadius="10px"
            android:topLeftRadius="10px"
            android:topRightRadius="10px" />
        <!-- 设置一下边距,让空间大一点 -->
        <padding
            android:bottom="5dp"
            android:left="5dp"
            android:right="5dp"
            android:top="5dp" />
            
    </shape>

    Step 3:将TextView的blackground属性设置成上面这两个Drawable:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF"
        android:gravity="center"
        android:orientation="vertical"
        tools:context=".MainActivity">
    
        <TextView
            android:id="@+id/txtOne"
            android:layout_width="200dp"
            android:layout_height="64dp"
            android:textSize="18sp"
            android:gravity="center"
            android:background="@drawable/txt_rectborder"
            android:text="矩形边框的TextView" />
    
        <TextView
            android:id="@+id/txtTwo"
            android:layout_width="200dp"
            android:layout_height="64dp"
            android:layout_marginTop="10dp"
            android:textSize="18sp"
            android:gravity="center"
            android:background="@drawable/txt_radiuborder"
            android:text="圆角边框的TextView" />
    
    
    </LinearLayout>
  • 相关阅读:
    CSS3实现平行四边形
    [Python]图的遍历-DFS
    [Python]图的遍历-BFS
    [Python]图的遍历-拓扑排序
    [Python]哈夫曼编码
    [Python]贪心算法-Prim-和-Kruskal实现-最小生成树
    [Python]贪心算法-Dijkstra-实现
    [python3]稳定匹配算法实现和优化
    从csv文件构建Tensorflow的数据集
    Tensorflow 基础API
  • 原文地址:https://www.cnblogs.com/wrx166/p/14909465.html
Copyright © 2011-2022 走看看