網(wǎng)站首頁 編程語言 正文
shape形狀之意,可自定義各種形狀,如背景橢圓,圓角等等
創(chuàng)建目錄:drawable–右鍵–new–drawable resourse file–鍵入文件名my_shape–ok–修改selector標(biāo)簽為shape
1圓角
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="10dp"/> </shape>
引用:android:background="@drawable/my_shape"
<Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="148dp" android:layout_marginTop="102dp" android:background="@drawable/my_shape" android:text="Button" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />
2 單獨控制某個圓角,如左上,右下。
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:topLeftRadius="10dp" android:bottomRightRadius="10dp" /> </shape>
3 圓形背景
前提button寬高一樣,圓角大小為button的一半大
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="100dp"/> </shape>
<Button android:id="@+id/button" android:layout_width="200dp" android:layout_height="200dp" android:layout_marginStart="148dp" android:layout_marginTop="102dp" android:background="@drawable/my_shape" android:text="Button" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />
3 描邊效果
注意此時用textview引用,botton無效
solid:實體,可設(shè)置主體顏色
stroke:描邊,dashWidth虛線寬度,dashGap虛線間的距離
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="50dp"/> <size android:height="100dp" android:width="100dp"/> <solid android:color="#FF4081"/> <stroke android:width="5dp" android:color="#3F51B5" android:dashWidth="20dp" android:dashGap="10dp"/> </shape>
引用
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="148dp" android:layout_marginTop="102dp" android:background="@drawable/my_shape" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>
4漸變色
gradient:傾斜度,標(biāo)簽實現(xiàn)
紅綠藍(lán)
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#ff0000" android:centerColor="#00ff00" android:endColor="#0000ff" /> </shape>
引用
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="148dp" android:layout_marginTop="102dp" android:text="Hello world" android:background="@drawable/my_shape_gradient" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>
拓展
1gradient標(biāo)簽?zāi)J(rèn)類型是線性的android:type=“l(fā)inear”,還有一種炫酷的效果是掃射sweep
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#ff0000" android:centerColor="#00ff00" android:endColor="#0000ff" android:type="sweep" /> </shape>
2確定逆時針旋轉(zhuǎn)的角度angle屬性,如android:angle="90"表示逆時針轉(zhuǎn)90度
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#ff0000" android:centerColor="#00ff00" android:endColor="#0000ff" android:angle="90" android:type="linear" /> </shape>
最后來一個好叼的樣子
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="@color/black" android:endColor="@color/black" android:centerColor="#FFFFFF" android:type="sweep"/> </shape>
原文鏈接:https://blog.csdn.net/xiyangyang8110/article/details/122715238
相關(guān)推薦
- 2022-07-23 C#中三種Timer計時器的詳細(xì)用法_C#教程
- 2022-06-21 C#多線程異步執(zhí)行和跨線程訪問控件Helper_C#教程
- 2023-01-05 淺析C++中的重載,隱藏和覆蓋_C 語言
- 2022-10-20 Android開發(fā)使用RecyclerView添加點擊事件實例詳解_Android
- 2022-06-20 Python使用PyAudio制作錄音工具的實現(xiàn)代碼_python
- 2022-04-12 el-form表單驗證的一些方法總結(jié)
- 2022-07-07 Python使用captcha庫制作帶參數(shù)輸入驗證碼案例_python
- 2022-06-29 C語言算法練習(xí)之折半查找的實現(xiàn)_C 語言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支