xml布局中实现文字下划线的效果

最近在项目中正好碰到需求:给文字实现下划线的效果,在网上搜索了下,有提供方法,但是我想完全依靠xml布局去实现,然后试验了几次,最终只用了TextView做出了如下效果:

这里写图片描述

下划线图片代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">

   <stroke
       android:width="1dp"
       android:color="#0042F4" />

   <size android:height="2dp"
       android:width="90dp"/>

</shape>

现在看TextView的设置:

?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginLeft="20dp"
              android:layout_marginRight="20dp"
              android:layout_marginTop="20dp"
              android:background="@drawable/system_bg1"
              android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:padding="10dp"
        android:text="请看如下的下划线效果图"
        android:textColor="#FFFFFF"
        android:textSize="18sp"/>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="50dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="1、"
            android:textColor="#0042F4"/>


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:drawablePadding="-3dp"
            android:drawableBottom="@drawable/underline"
            android:gravity="center"
            android:text="下划线下划线"
            android:textColor="#0042F4"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="50dp"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="2、"
            android:textColor="#0042F4"/>


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:drawableBottom="@drawable/underline1"
            android:gravity="center"
            android:drawablePadding="-3dp"
            android:text="下划线下划线"
            android:textColor="#0042F4"/>
    </LinearLayout>


</LinearLayout>

以上就是完全依靠xml布局实现的。其中我认为最关键的一步就是在TextView中将drawablePadding设置为负值。将字体和图片之间的间距进一步缩小,实现了下划线的效果。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
XML文件实现inner join效果需要使用XML文档对象模型(DOM)或XML数据文档(XQuery)来查询和操作XML数据。下面是一个简单的例子: 假设有两个XML文件:orders.xml和customers.xml。orders.xml文件包含订单信息,customers.xml文件包含客户信息。为了实现inner join效果,需要将这两个文件相关的信息进行匹配。 orders.xml文件: ``` <orders> <order id="1" customerId="101" total="100.00" /> <order id="2" customerId="102" total="200.00" /> <order id="3" customerId="101" total="150.00" /> </orders> ``` customers.xml文件: ``` <customers> <customer id="101" name="John Smith" /> <customer id="102" name="Jane Doe" /> </customers> ``` 使用DOM实现inner join效果: ``` // 加载orders.xml和customers.xml文件 var ordersDoc = loadXMLDoc("orders.xml"); var customersDoc = loadXMLDoc("customers.xml"); // 获取orders和customers节点 var orders = ordersDoc.getElementsByTagName("order"); var customers = customersDoc.getElementsByTagName("customer"); // 遍历orders和customers节点,匹配相关信息 for (var i = 0; i < orders.length; i++) { var order = orders[i]; var customerId = order.getAttribute("customerId"); for (var j = 0; j < customers.length; j++) { var customer = customers[j]; var id = customer.getAttribute("id"); if (customerId == id) { // 输出匹配结果 console.log("Order #" + order.getAttribute("id") + " belongs to " + customer.getAttribute("name")); } } } ``` 使用XQuery实现inner join效果: ``` let $orders := doc("orders.xml")/orders/order let $customers := doc("customers.xml")/customers/customer for $order in $orders let $customer := $customers[@id = $order/@customerId][1] return <order> { $order/@* } { $customer/@name } </order> ``` 这个XQuery查询将返回一个包含订单信息和客户名称的XML结果集。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值