當前位置:首頁 » 安卓系統 » android代碼shape

android代碼shape

發布時間: 2022-06-14 12:58:42

① android 里用shape畫圓,怎麼填充顏色

Android裡面使用shape設置控制項的外形,例如一些圓角、填充的背景顏色、以及一些漸變的效果等,所以設置填充顏色,可通過設置shape.xml文件里的如下屬性:

1

<solid android:color="@color/common_red" />

將shape文件放到android的button、textview組件上,就可以有填充背景顏色的效果,完整的代碼如下:
1.shape.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false" >
<solid android:color="@color/common_red" />
<padding
android:left="2dp"
android:top="1dp"
android:right="2dp"
android:bottom="1dp" />
<solid
android:color="@color/common_red" />
<stroke
android:width="1dp"
android:color="@android:color/white" />
<size android:width="15dp"
android:height="15dp" />

2011年醫師資格考試合格標准 356
2010年醫師資格考試合格標准 351
2009年醫師資格考試合格標准 345
2008年醫師資格考試合格標准 359
醫師資格證書是國內行醫必不可少的"通行證",科目醫師資格考試是評價申請醫師資格者是否具備從事醫師工作所必須通過的考試。
2014鄉執業助理醫師成績已公布,鄉鎮執業助理醫師成績也同時公布,國家醫學考試中心查。
鄉鎮執業助理醫師分數線需等各省公布各省的。會在這段時間之內全部公布請耐心等待!

② android shape solid 如何在代碼中設置

在XML文件里設置,然後在需要的控制項上用background屬性引用
比如:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="#ffda7585" /> <!-- 內容顏色 -->
<stroke android:width="1.0dip" android:color="#50cccccc" /> <!-- 邊框大小、顏色-->
<corners android:radius="10.0dip" /> <!-- 圓角弧度 -->
</shape>
</item>
</selector>

③ 安卓在代碼中設置Textview的shape,怎麼設置

res目錄下面創建一個文件夾drawable,裡面創建一個xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="3dp"/>
<stroke android:width="0.7dp"
android:color="#000000" />
<!--下面為背景填充色,需要跟上面的進行區別 -->
<solid android:color="#ffffff"/>
</shape>

④ android 中既要設置shape 又要設置selector 怎麼辦

shape和selector的結合使用
shape和selector是Android UI設計中經常用到的,比如我們要自定義一個圓角Button,點擊Button有些效果的變化,就要用到shape和selector。可以這樣說,shape和selector在美化控制項中的作用是至關重要的。

1.Shape
簡介
作用:XML中定義的幾何形狀
位置:res/drawable/文件的名稱.xml
使用的方法:
java代碼中:R.drawable.文件的名稱
XML中:Android:background="@drawable/文件的名稱"
屬性:
<shape> Android:shape=["rectangle" | "oval" | "line" | "ring"]
其中rectagle矩形,oval橢圓,line水平直線,ring環形
<shape>中子節點的常用屬性:
<gradient> 漸變
Android:startColor 起始顏色
Android:endColor 結束顏色
Android:angle 漸變角度,0從上到下,90表示從左到右,數值為45的整數倍默認為0;
Android:type 漸變的樣式 liner線性漸變 radial環形漸變 sweep
<solid > 填充
Android:color 填充的顏色
<stroke > 描邊
Android:width 描邊的寬度
Android:color 描邊的顏色
Android:dashWidth 表示'-'橫線的寬度
Android:dashGap 表示'-'橫線之間的距離
<corners > 圓角
Android:radius 圓角的半徑 值越大角越圓
Android:topRightRadius 右上圓角半徑
Android:bottomLeftRadius 右下圓角角半徑
Android:topLeftRadius 左上圓角半徑
Android:bottomRightRadius 左下圓角半徑
2.Selector
簡介
位置:res/drawable/文件的名稱.xml
使用的方法:
Java代碼中:R.drawable.文件的名稱
XML中:Android:background="@drawable/文件的名稱"
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:Android="http://schemas.android.com/apk/res/android">
<!-- 默認時的背景圖片-->
<item Android:drawable="@drawable/pic1" />
<!-- 沒有焦點時的背景圖片 -->
<item
Android:state_window_focused="false"
android:drawable="@drawable/pic_blue"
/>
<!-- 非觸摸模式下獲得焦點並單擊時的背景圖片 -->
<item
Android:state_focused="true"
android:state_pressed="true"
android:drawable= "@drawable/pic_red"
/>
<!-- 觸摸模式下單擊時的背景圖片-->
<item
Android:state_focused="false"
Android:state_pressed="true"
Android:drawable="@drawable/pic_pink"
/>
<!--選中時的圖片背景-->
<item
Android:state_selected="true"
android:drawable="@drawable/pic_orange"
/>
<!--獲得焦點時的圖片背景-->
<item
Android:state_focused="true"
Android:drawable="@drawable/pic_green"
/>
</selector>
第一個例子:圓角的Button
第二個例子:shape+selector綜合使用的例子 漂亮的ListView
selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:Android="http://schemas.android.com/apk/res/android">
<item Android:state_selected="true">
<shape>
<gradient Android:angle="270" android:endColor="#99BD4C"
android:startColor="#A5D245" />
<size Android:height="60dp" android:width="320dp" />
<corners android:radius="8dp" />
</shape>
</item>
<item Android:state_pressed="true">
<shape>
<gradient Android:angle="270" android:endColor="#99BD4C"
android:startColor="#A5D245"/>
<size Android:height="60dp" android:width="320dp" />
<corners android:radius="8dp" />
</shape>
</item>
<item>
<shape>
<gradient Android:angle="270" android:endColor="#A8C3B0"
android:startColor="#C6CFCE" />
<size Android:height="60dp" android:width="320dp" />
<corners android:radius="8dp" />
</shape>
</item>
</selector>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
Android:layout_width="fill_parent"
android:layout_height="wrap_content"
Android:background="@drawable/selector"
>
<ImageView
Android:id="@+id/img"
Android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
/>
<TextView
Android:text="data"
android:id="@+id/title"
Android:layout_width="fill_parent"
android:layout_height="wrap_content"
Android:gravity="center_vertical"
android:layout_marginLeft="20dp"
Android:layout_marginTop="20dp"
android:textSize="14sp"
Android:textStyle="bold"
android:textColor="@color/black"
>
</TextView>
</LinearLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
Android:layout_width="fill_parent"
android:layout_height="wrap_content"
Android:background="#253853"
>
<ListView
Android:id="@+id/list"
Android:layout_width="match_parent"
android:layout_height="match_parent"
Android:cacheColorHint="#00000000"
android:divider="#2A4562"
Android:dividerHeight="3px"
android:listSelector="#264365"
Android:drawSelectorOnTop="false"
>
</ListView>
</LinearLayout>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFFFF</color>
<color name="transparency">#00000000</color>
<color name="title_bg">#1C86EE</color>
<color name="end_color">#A0cfef83</color>
<color name="black">#464646</color>
</resources>
MainActivity.xml
package com.ling.customlist;
import java.util.ArrayList;
import java.util.HashMap;
import xb.customlist.R;
import Android.R.array;
import android.app.Activity;
import Android.os.Bundle;
import android.widget.ArrayAdapter;
import Android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity {
ListView list;
String data[] = new String[]{
"China","UK","USA","Japan","German","Canada","ET","Narotu"
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list =(ListView) findViewById(R.id.list);
SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.list_item,
new String[]{"title","img"}, new int[]{R.id.title,R.id.img});
list.setAdapter(adapter);
}
private ArrayList<HashMap<String, Object>> getData() {
ArrayList<HashMap<String, Object>> dlist = new ArrayList<HashMap<String,Object>>();
for(int i =0;i<data.length;i++){
HashMap<String, Object>map = new HashMap<String, Object>();
map.put("title", data[i]);
map.put("img", R.drawable.item_left2);
dlist.add(map);
}
return dlist;
}
}

⑤ android 圓角樣式shape 的shape屬性什麼意思

shape官方給出了很多屬性的解釋,如下:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
><!-- 其中rectagle表示矩形,oval表示橢圓,line表示水平直線,ring表示環形 -->
<!-- 節點屬性介紹如下 -->
<corners />
<!-- 節點1:corners (圓角)
android:radius 圓角的半徑 值越大角越圓
android:topLeftRadius 左上圓角半徑
android:topRightRadius 右上圓角半徑
android:bottomLeftRadius 左下圓角半徑
android:bottomRightRadius 右下圓角半徑
-->

<gradient />
<!-- 節點2: gradient (背景顏色漸變)
android:startColor 起始顏色
android:centerColor 中間顏色
android:endColor 末尾顏色
android:angle 漸變角度,必須為45的整數倍。
android:type 漸變模式 默認是linear(線性漸變)radial(環形漸變)
android:centerX X坐標
android:centerY Y坐標
android:gradientRadius radial(環形漸變)時需指定半徑
-->

<padding />
<!-- 節點3: padding (定義內容離邊界的距離)
android:left 左部邊距
android:top 頂部邊距
android:right 右部邊距
android:bottom 底部邊距
-->

<size />
<!-- 節點4:size (大小)
android:width 指定寬度
android:height 指定高度
-->

<solid />
<!-- 節點5:solid (填充)
android:color 指定填充的顏色
-->

<stroke />
<!-- 節點6:stroke (描邊)
android:width 描邊的寬度
android:color 描邊的顏色
把描邊弄成虛線的形式"- - -":
android:dashWidth 表示'-'這樣一個橫線的寬度
android:dashGap 表示之間隔開的距離
-->

</shape></span>

⑥ 怎麼在安卓代碼中使用自己定義的shape

在drawable文件夾中創建bg_oval_shape/apk/res/android" android:shape="oval" > <solid android:color="#676767" /> </shape> 3.在需要添加oval的控制項中引用,代碼如下: <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/bg_oval_shape"/>

⑦ android怎樣在代碼中創建shape圓oval

  1. 在drawable文件夾中創建bg_oval_shape.xml的xml文件

  2. 文件中添加如下代碼

<?xmlversion="1.0"encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#676767"/>

</shape>

3.在需要添加oval的控制項中引用,代碼如下:

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bg_oval_shape"/>

⑧ android中如何使用shape來顯示直角三角形

用一個rectangle的shape,再用一個rotate標簽包裹這個shape,設置rotate標簽的fromDegree為30,pivotX為0%,pivotY為100%。

意思就是對矩形做一個旋轉,讓它變成直角三角形。

⑨ android 怎樣用shape畫一個倆邊半圓的按鈕背景

用shape畫一個倆邊半圓的按鈕,可以用圖形畫。
Circle方法用來畫圓、橢圓、圓弧和餅分圖。
畫圓,Visual Basic需要給出這個圓的圓心位置和它的半徑:「對象. Circle Step (x, y),半徑,顏色」。
如果不指定對象,指定的就是當前的窗體。
用繪圖區的標尺屬性,可以使圓心置於繪圖區域的中心處。

⑩ android如何創建平行四邊形 shape 背景嗎

作為選擇到 @mmlooloo 的答案,其中歸功於,我建議一個 xml 可繪制的解決方案 (因為你沒有強調什麼樣的你正在尋找的解決方案)。在下面的示例使用一般 View ,但您可以使用任何其他。
這里是View
<View
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:background="@drawable/shape" />
和 shape.xml 本身
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="" >
<!-- Colored rectangle-->
<item>
<shape android:shape="rectangle">
<size
android:width="100dp"
android:height="40dp" />
<solid android:color="#13a89e" />
</shape>
</item>
<!-- This rectangle for the left side -->
<!-- Its color should be the same as layout's background -->
<item
android:right="100dp"
android:left="-100dp"
android:top="-100dp"
android:bottom="-100dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
<!-- This rectangle for the right side -->
<!-- Their color should be the same as layout's background -->
<item
android:right="-100dp"
android:left="100dp"
android:top="-100dp"
android:bottom="-100dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
</layer-list>

熱點內容
寶塔資料庫備份 發布:2025-05-18 02:14:18 瀏覽:192
安卓商店下載的光遇是什麼服 發布:2025-05-18 02:13:38 瀏覽:31
網頁挖礦源碼 發布:2025-05-18 02:13:34 瀏覽:307
centosftp伺服器設置參數 發布:2025-05-18 02:12:55 瀏覽:216
賬號密碼保存在瀏覽器哪裡 發布:2025-05-18 01:56:43 瀏覽:833
ftp不輸入密碼 發布:2025-05-18 01:54:27 瀏覽:671
壓縮旗袍 發布:2025-05-18 01:52:58 瀏覽:198
海上傳奇南昌 發布:2025-05-18 01:40:31 瀏覽:131
php怎麼訪問地址 發布:2025-05-18 01:29:43 瀏覽:321
fbe加密 發布:2025-05-18 01:16:34 瀏覽:251