當前位置:首頁 » 安卓系統 » android圓角邊框樣式

android圓角邊框樣式

發布時間: 2023-08-07 00:52:35

1. android 圓角邊框 陰影邊框怎麼設置

所謂添加陰影,就是兩個畫布從重疊,上方的畫布小於下方的畫布,陰影顏色為下方的畫布的顏色。
item 中shape 的屬性 (rectangle:矩形;line:線性;oval:橢圓;ring:環形),默認為矩形
corners //設置圓角幅度,必須是在shape=rectangle的時候,corners才有效
<corners
Android:radius="dimension" //全部的圓角半徑
android:topLeftRadius="dimension" //左上角的圓角半徑
android:topRightRadius="dimension" //右上角的圓角半徑
android:bottomLeftRadius="dimension" //左下角的圓角半徑
android:bottomRightRadius="dimension" /> //右下角的圓角半徑
eg:<corners android:radius="10dp" />
solid用以指定內部填充色
e.g:<solid android:color="color" />
gradient //定義漸變色,可以定義兩色漸變和三色漸變,及漸變樣式
linear(線性漸變)、radial(放射性漸變)、sweep(掃描式漸變), 在構造放射性漸變時,要加上android:gradientRadius屬性(漸變半徑),即必須指定漸變半徑的大小才會起作用。
<gradient
android:type=["linear" | "radial" | "sweep"] //共有3中漸變類型
android:angle="integer" //漸變角度,必須為45的倍數,0為從左到右,90為從上到下
android:centerX="float" //漸變中心X的相當位置,范圍為0~1
android:centerY="float" //漸變中心Y的相當位置,范圍為0~1
android:startColor="color" //漸變開始點的顏色
android:centerColor="color" //漸變中間點的顏色,在開始與結束點之間
android:endColor="color" //漸變結束點的顏色
android:gradientRadius="float" //漸變的半徑,只有當漸變類型為radial時才有效
android:useLevel=["true" | "false"] /> //使用LevelListDrawable時就要設置為true。設為false時才有漸變效果
stroke //這是描邊屬性,可以定義描邊的寬度,顏色,虛實線等
<stroke
android:width="dimension" //描邊的寬度
android:color="color" //描邊的顏色 // 以下兩個屬性設置虛線
android:dashWidth="dimension" //虛線的寬度,值為0時是實線
android:dashGap="dimension" /> //虛線的間隔

2. Android studio中怎麼將方形按鈕設置成圓角以及漸變效果

一、在 studio中res 包下的drawable中建立一個shape的文件,系統會給你一個默認的方形然後你就可以開始設置你需要的效果。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:Android="http://schemas.android.com/apk/res/android">

<!--填充背景色 -->
<solid android:color="#ffff00" /> //solid 指的是背景顏色的設置

<!--描邊 他需要 2個參數,顏色 第二參數 寬度 -->
<stroke
android:width="2dp" //width 指的是邊框的寬度
android:color="#ff00ff" /> //color指的是邊框的顏色

<!-- 設置弧度 Radius設置所有角的弧度 --> //radius 指的就是角的弧度
<corners //方形存在四個角,我們可以同時設置四個角,也可以分開設置
android:bottomLeftRadius="20dp" //左下角
android:bottomRightRadius="20dp" //右下角
android:topLeftRadius="20dp" //左上角
android:topRightRadius="20dp" /> //右上角

//同時設置:<corners
android:Radius="20dp" /> //四個角同時設置

<!-- 漸變色 startColor 啟示顏色 endColor最終顏色 type類型(如果類型為radial(徑向漸變,一個圓心以半徑的方式漸變),必須加上 android:gradientRadius="**")-->
<gradient
android:startColor="#ff0000" //開始顏色
android:endColor="#ffffff" //結束顏色
android:type="linear" /> //水平漸變 從左到右 type 指的是漸變的模式

<!--內容與邊框的間距-->
<padding
android:bottom="15dp"
android:left="15dp"
android:right="15dp"
android:top="15dp" />

<!--如果設置了漸變色 那麼背景顏色將不顯示 -->

</shape>
<gradient>
shape的顏色漸變屬性
attributes:

android:angle
Integer,代表漸變顏色的角度, 0 is left to right, 90 is bottom to top. 必須是45的整數倍.
默認是 0.該屬性只有在type=linear情況下起作用,默認的type為linear。
默認情況下,從左到右:

xml代碼:<gradient
android:startColor="#000000"
android:endColor="#ffffff"
/>

angle=270,從上到下 :

xml代碼:<gradient
android:startColor="#000000"
android:endColor="#ffffff"
android:angle="270"
/>
android:startColor
Color. 顏色漸變的開始顏色,如angle=270中的 android:startColor="#000000"
android:endColor
Color. 顏色漸變的結束顏色,如angle=270中的 android:endColor="#ffffff"
android:centerColor
Color. 顏色漸變的中間顏色,主要用於多彩。

<gradient
android:startColor="#000000"
android:endColor="#ffffff"
android:centerColor="#ff0000"
/>
android:centerX
Float.(0 - 1.0) 相對X的漸變位置。
android:centerY
Float.(0 - 1.0) 相對Y的漸變位置。
這兩個屬性只有在type不為linear情況下起作用。
android:gradientRadius
Float. 漸變顏色的半徑,單位應該是像素點. 需要 android:type="radial".
如果android:type="radial",沒有設置android:gradientRadius,將會報錯,error inflating class.

xml代碼:
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.5"
android:centerY="0.5"
android:gradientRadius="30"
android:type="radial"
/>
加入Android:centerColor屬性

<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerColor="#000000"
android:centerX="0.5"
android:centerY="0.5"
android:gradientRadius="30"
android:type="radial"
/>
android:type
Value Description
"linear" 線性漸變.可以理解為 y=kx+b.
"radial" A radial gradient.圓形漸變,起始顏色從cenralX,centralY點開始。
"sweep" A sweeping line gradient.

centerX="0.2" centerX="0.2"

xml代碼:
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.2"
android:centerX="0.2"
android:gradientRadius="30"
android:type="radial"
/>
type="sweep":

xml代碼:
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.5"
android:centerY="0.5"
android:type="sweep"
/>

3. Android圓角背景設置

使用databinding設置圓角背景,代替drawable方式

注意:這個只是設置一個背景,所有圖片的圓角不能使用它,只能是viewGroup或者TextView。
提示:圖片可以使用QMUIRadiusImageView

1、支持view和viewGroup的圓角,邊框、和單個圓角等;
2、app:bgRadius:圓角大小,必須用"@{R.dimen.ui_dp8}"賦值;
3、app:bgSolidColor:設置背景色;
4、app:bgStrokeColor:設置邊框顏色;
5、bgTopLeftRadius:設置左上的圓角;

4. Android studio圓角矩形的布局如何設計

你可以使用shape定義一個圓角矩形,並將其作為布局的背景即可。
圓角矩形的shape代碼如下:
//定義四個圓角 文件名shape_round_corner
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ff00" />
<corners android:topLeftRadius="12dp"
android:topRightRadius="12dp"
android:bottomRightRadius="12dp"
android:bottomLeftRadius="12dp"/>
<stroke android:width="1dp" android:color="#ff0" />
</shape>
設置背景代碼如下:
<LinearLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:alpha="0.8"
android:background="@drawable/shape_round_corner">
</LinearLayout>

5. Android中使用CardView實現圓角對話框

前言:隨著用戶體驗的不斷的加深,良好的UI視覺效果也必不可少,以前方方正正的對話框樣式在APP已不復存在,取而代之的是帶有圓角效果的Dialog,之前設置對畫框的圓角效果都是通過drawable/shape屬性來完成,隨著Google API的不斷更新,API 21(Android 5.0)添加了新的控制項CardView,這使得圓角的實現更加方便快捷。

效果圖:

導入CardView依賴(API 21新控制項)

1.cardCornerRadius屬性:設置圓角的弧度大小,這里設置的為10dp

2.CardView還有padding、cardUseCompatPadding(內邊距)、background等屬性

3.CardView繼承自FrameLayout,使用時可以重新嵌套布局

使用的是V7包的AlertDialog實現的,當然也可以使用Dialog實現。

總結:CardView實現對話框的圓角效果更加的方便,不用編寫shape屬性設置背景,當標題欄需要背景色時,也無需考慮設置標題欄的shape背景(不使用CardView時,如果不使用shape設置背景色,會導致左上和右上不會變成圓角)。

6. Android:如下關於繪制圓角矩形邊框問題,怎麼解決

paint.setAntiAlias(true);

嘗試在畫筆上設置抗鋸齒

熱點內容
r7000p2021買哪個配置 發布:2025-02-04 06:40:17 瀏覽:965
如何消除微信小程序緩存 發布:2025-02-04 06:34:24 瀏覽:633
python27mysqldb 發布:2025-02-04 06:28:44 瀏覽:768
svn文件夾許可權 發布:2025-02-04 06:23:47 瀏覽:901
師編程 發布:2025-02-04 06:22:51 瀏覽:169
加密類型wpa 發布:2025-02-04 06:21:27 瀏覽:178
互聯網與雲伺服器 發布:2025-02-04 06:15:56 瀏覽:254
硬碟挖礦源碼 發布:2025-02-04 06:15:45 瀏覽:76
寶馬3系哪個配置合適 發布:2025-02-04 06:03:10 瀏覽:328
磁碟存儲器的管理課後答案 發布:2025-02-04 05:58:58 瀏覽:600