android 气泡尖角边框,如何使用CSS实现一个带尖角的气泡框?

今天的任务中遇上了一个气泡框,还有需要添加圆角和指向性尖角,所以打开百度默默学习了一波,此文仅供自己记录使用。

先来看看预览图

8df6a627708c43831266669f74d75625.png

先写上盒子,上代码

HTML:

CSS:

.element{

width: 0;

height: 0;

border-top: 20px solid red;

border-right: 20px solid blue;

border-bottom: 20px solid #727171;

border-left: 20px solid palegoldenrod;

}

复制代码

实现效果如下:6565f11c1ea34f8d7d1d653090138cbe.png

具体的实现原理呢,一个盒子,作为一个块级元素,我们首先将它的宽和高都设置成0,再将边框的大小设置成20px,也就是形成了如上图这样的四等分三角形组成的一个正方形。

那我们要得到一个方向朝上的尖角,就必须让上,右,左的三角形“隐形”。透明属性可以帮助我们做到这一点,透明的背景欺骗了我们的眼睛~让

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 Android 气泡框代码示例: 首先,创建一个自定义的布局文件 `custom_tooltip.xml`,包含一个 LinearLayout 和一个 TextView: ``` <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tooltip_container" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/tooltip_background" android:orientation="horizontal" android:padding="8dp"> <TextView android:id="@+id/tooltip_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/white" /> </LinearLayout> ``` 然后,在你的 Activity 中,使用 PopupWindow 来显示气泡框。示例代码如下: ``` // inflate the custom layout View tooltipView = LayoutInflater.from(this).inflate(R.layout.custom_tooltip, null); // set the text of the TextView TextView tooltipText = tooltipView.findViewById(R.id.tooltip_text); tooltipText.setText("Hello, world!"); // create a new PopupWindow PopupWindow tooltip = new PopupWindow(tooltipView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); // set the PopupWindow to be focusable tooltip.setFocusable(true); // show the PopupWindow at a specified location int[] location = new int[2]; targetView.getLocationOnScreen(location); tooltip.showAtLocation(targetView, Gravity.NO_GRAVITY, location[0], location[1] - tooltip.getHeight()); ``` 这里,`targetView` 是你想要在其上显示气泡框的 View。`location` 数组包含 `targetView` 在屏幕上的 x 和 y 坐标。我们使用 `showAtLocation` 方法来显示气泡框,并将其放置在 `targetView` 的下方。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值