當前位置:首頁 » 安卓系統 » androidring

androidring

發布時間: 2022-12-25 21:01:36

A. android 怎麼畫2層圓環

Android繪制兩層圓環,可以使用自定義View,繼承View,重寫裡面的Ondraw方法,花兩個同心圓,示例如下:

java">packagecom.cn.myvn;

importandroid.content.Context;
importandroid.graphics.Canvas;
importandroid.graphics.Paint;
importandroid.util.AttributeSet;
importandroid.view.View;

{

privatefinalPaintpaint;
privatefinalContextcontext;

publicRingView(Contextcontext){

//TODOAuto-generatedconstructorstub
this(context,null);
}

publicRingView(Contextcontext,AttributeSetattrs){
super(context,attrs);
//TODOAuto-generatedconstructorstub
this.context=context;
this.paint=newPaint();
this.paint.setAntiAlias(true);//消除鋸齒
this.paint.setStyle(Paint.Style.STROKE);//繪制空心圓
}

@Override
protectedvoidonDraw(Canvascanvas){
//TODOAuto-generatedmethodstub
intcenter=getWidth()/2;
intinnerCircle=dip2px(context,83);//設置內圓半徑
intringWidth=dip2px(context,5);//設置圓環寬度

//繪制內圓
this.paint.setARGB(155,167,190,206);
this.paint.setStrokeWidth(2);
canvas.drawCircle(center,center,innerCircle,this.paint);

//繪制圓環
this.paint.setARGB(255,212,225,233);
this.paint.setStrokeWidth(ringWidth);
canvas.drawCircle(center,center,innerCircle+1+ringWidth/2,this.paint);

//繪制外圓
this.paint.setARGB(155,167,190,206);
this.paint.setStrokeWidth(2);
canvas.drawCircle(center,center,innerCircle+ringWidth,this.paint);

super.onDraw(canvas);
}
}

B. 怎麼在android上面做出根據形狀來漸變的效果

<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 左下圓角半徑
<padding >填充
android:bottom="1.0dip" 底部填充
android:left="1.0dip" 左邊填充
android:right="1.0dip" 右邊填充
android:top="0.0dip" 上面填充
Selector
根據不同的選定狀態來定義不同的現實效果 分為四大屬性:
android:state_selected 是選中
android:state_focused 是獲得焦點
android:state_pressed 是點擊
android:state_enabled 是設置是否響應事件,指所有事件
android:state_window_focused 默認時的背景圖片 引用位置: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>

layer-list(多個shape)
將多個圖片或上面兩種效果按照順序層疊起來
示例:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/android_red"
android:gravity="center" />
</item>
<item android:top="10dp" android:left="10dp">
<bitmap android:src="@drawable/android_green"
android:gravity="center" />
</item>
<item android:top="20dp" android:left="20dp">
<bitmap android:src="@drawable/android_blue"
android:gravity="center" />
</item>
</layer-list>

感覺很像多個drawable
三者可以結合使用
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item android:bottom="8.0dip">
<shape>
<solid android:color="#ffaaaaaa" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="4.0dip" android:bottomRightRadius="4.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="#ffaaaaaa" />

<padding android:bottom="1.0dip" android:left="1.0dip" android:right="1.0dip" android:top="0.0dip" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="3.0dip" android:bottomRightRadius="3.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="@color/setting_item_bgcolor_press" />
</shape>
</item>
</layer-list>
</item>
<item>
<layer-list>
<item android:bottom="8.0dip">
<shape>
<solid android:color="#ffaaaaaa" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="4.0dip" android:bottomRightRadius="4.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="#ffaaaaaa" />

<padding android:bottom="1.0dip" android:left="1.0dip" android:right="1.0dip" android:top="0.0dip" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="3.0dip" android:bottomRightRadius="3.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="@color/setting_item_bgcolor" />
</shape>
</item>
</layer-list>
</item>
</selector>

C. 關於android中RingtoneManager的問題

RingtoneManager是android的鈴聲管理器。
具體實現代碼:
package rocka.media.ringtong;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Media_RingTongActivity extends Activity {
//定義三個按鈕
private Button mRingtongButton;
private Button mAlarmButton;
private Button mNotificationButton;

//定義類型
private static final int RingtongButton=0;
private static final int AlarmButton=1;
private static final int NotificationButton=2;

//鈴聲文件夾
private String strRingtongFolder="/sdcard/media/ringtones";
private String strAlarmFolder="/sdcard/media/alarms";
private String strNotificationFolder="/sdcard/media/notifications";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mRingtongButton=(Button)findViewById(R.id.myRingtongButton);
mRingtongButton.setOnClickListener(new myRingtongButtonListener());
mAlarmButton=(Button)findViewById(R.id.myAlarmButton);
mAlarmButton.setOnClickListener(new myAlarmButtonListener());
mNotificationButton=(Button)findViewById(R.id.myNotificationButton);
mNotificationButton.setOnClickListener(new myNotificationButtonListener());
}

//設置來電鈴聲監聽器
private class myRingtongButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
if(isFolder(strRingtongFolder)){
//打開系統鈴聲設置
Intent intent=new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, true);
//類型為來電ringtong
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
//設置顯示的題目
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "設置來電的鈴聲");
//當設置完成之後返回到當前的activity
startActivityForResult(intent, RingtongButton);
}
}
}

//設置鬧鍾鈴聲監聽器
private class myAlarmButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
if(isFolder(strAlarmFolder)){
Intent intent=new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "設置鬧鈴鈴聲");
startActivityForResult(intent, AlarmButton);
}
}
}

//設置通知鈴聲監聽器
private class myNotificationButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
if(isFolder(strNotificationFolder)){
Intent intent=new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "設置通知鈴聲");
startActivityForResult(intent, NotificationButton);
}
}
}
//檢查是否存在指定的文件夾,如果不存在就創建
private boolean isFolder(String strFolder){
boolean tmp = false;
File f1 = new File(strFolder);
if (!f1.exists())
{
if (f1.mkdirs())
{
tmp = true;
}
else
{
tmp = false;
}
}
else
{
tmp = true;
}
return tmp;
}
//設置鈴聲之後的回調函數
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode!=RESULT_OK){
return;
}
switch(requestCode){
case RingtongButton:
try {
//得到選擇的鈴聲
Uri pickedUri=data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
//將選擇的鈴聲選擇成默認
if(pickedUri!=null){
RingtoneManager.setActualDefaultRingtoneUri(Media_RingTongActivity.this, RingtoneManager.TYPE_RINGTONE, pickedUri);
}
} catch (Exception e) {
e.printStackTrace();
}
break;
case AlarmButton:
try {
//得到選擇的鈴聲
Uri pickedUri=data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
//將我們選擇的鈴聲選擇成默認
if(pickedUri!=null){
RingtoneManager.setActualDefaultRingtoneUri(Media_RingTongActivity.this, RingtoneManager.TYPE_ALARM, pickedUri);
}
} catch (Exception e) {
e.printStackTrace();
}
break;
case NotificationButton:
try {
//得到選擇的鈴聲
pickedUri=data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
//將選擇的鈴聲選擇成默認
if(pickedUri!=null){
RingtoneManager.setActualDefaultRingtoneUri(Media_RingTongActivity.this, RingtoneManager.TYPE_NOTIFICATION, pickedUri);
}
} catch (Exception e) {
e.printStackTrace();
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
}

代碼說明:
1.布局文件就是三個按鈕。
2.在真機測試了一下,可以運行,在模擬器測試要注意了,每次把音頻文件push到sdcard中得時候,必須重啟模擬器,模擬器才會應用設置,不然是檢索不到的。
3.系統的原始聲音存放在/system/media/audio/文件中 。
4.最後一點不要忘記給應用程序加許可權了:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>

D. Android中shape用法詳解

android:shape 屬性有矩形(默認)[ rectangle ]、橢圓形[ oval ]、直線性[ line ]和環形[ ring ]
其中當屬性為環形[ ring ]時,還可以設置如下屬性:

E. 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"/>

F. android 畫背景 shapeDrawable 中的 ring 和 line 怎麼顯示出來難道這兩個屬性是用來坑爹的。

肯定是有用的,只是你沒找到怎麼用。

剛寫的,你試下我寫的這個:

<?xmlversion="1.0"encoding="utf-8"?>

<shapexmlns:android="
http://schemas.android.com/apk/res/android
"android:shape="ring">

<gradientandroid:startColor="#FFF000"

android:centerColor="#0F0F00"

android:endColor="#00F0FF"

android:type="radial"

android:gradientRadius="50"/>

</shape>

對應的layout控制項:

<ProgressBar

style="?android:attr/progressBarStyleLarge"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:indeterminateDrawable="@drawable/ring_shape"/>

我這邊是可以正確顯示的

G. android setringmode 怎麼會靜音

把媒體音關掉

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

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

<solidandroid:color="@color/common_red"/>

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

1.shape.xml

<?xmlversion="1.0"encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false">
<solidandroid: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"/>
<sizeandroid:width="15dp"
android:height="15dp"/>
</shape>


2.把以上代碼添加到drawable裡面、通過background引用就可以了

<TextView
android:id="@id/message_category_unread_count"
style="@style/comm_text_style_14_aaaaaa"
android:layout_marginLeft="70dp"
android:layout_marginTop="5dp"
android:background="@drawable/shape"
android:gravity="center"
android:textSize="@dimen/text_size_comment_20"
android:text="7"
android:textColor="@android:color/white"/>

效果如下圖:

I. android中常用的資源有哪些

Android 資源類型
1.字元串資源

>>1.普通字元串
>>2.字元串數組

復制代碼
<resources>
<string-array name="planets_array">
<item>aaa</item>
<item>bbb</item>
</string-array>
</resources>
復制代碼
獲取方式:getResources().getStringArray(R.array.planets_array)
>>3.復數字元串資源
某些自然語言中,不同的數字在使用方法上會有所不同,比如one book,two books。當數量大於1時,會使用不同的名詞或其它復數形式;

復制代碼
<resources>
<plurals name="numberOfp">
<item quantity="one">one person</item>
<item quantity="other">more persons</item>
</plurals>
</resources>
復制代碼
quantity屬性的值除了one和other外,還可以是zero,two,few,many;
引用復數字元串:
// 引用數字為1的復數字元串
getResources().getQuantityString(R.pluarlas.numberOfp,1);
// 引用數字為其它值的復數字元串
getResources().getQuantityString(R.pluarlas.numberOfp,10,10);
>>4.佔位符格式化字元串
常用的格式化字元串三種方法:
>>1.在字元串中使用引號
字元串中的值雖然可以隨意指定,但是當遇到特殊符號時(雙引號,單引號)就需要採取特殊的方法來處理這些符號。
如果是單引號(')可以使用轉義符(\)或用雙引號(")將整個字元串括起來,如果是雙引號,可以在雙引號前使用轉義符(\)。

<resources>
<string name="str1">"This'll work"</string> This'll work
<string name="str2">This\'ll work</string> This'll work
<string name="str3">\"apple\"</string> "apple"
</resources>
>>2.用佔位符格式化字元串
使用String.format(String,Object...)方法可以格式化帶佔位符的字元串,只需要在字元串中插入佔位符,就可以使用String.format方法格式化字元串資源,format方法要求的佔位符用%1,%,...,%n,其實第n個佔位符與format方法的n+1個參數值對應;

<resources>
<!-- $s表示該佔位符被字元串替換,$d表示該佔位符被整數替換 -->
<string name="str1">hello,%1$s!You have %2$d new message</string>
</resources>
String str1 =String.format(getResources().getString(R.string.str1), "ly", 17);
>>3.使用HTML標簽格式化字元串資源

字元串資源支持一些HTML標簽,因此可以直接在字元串資源中使用這些HTML標簽格式化字元串
字元串資源支持如下的HTML標簽
<b>粗體字
<i>斜體定
<u>帶下劃線的字
有時需要同時使用HTML標簽和佔位符格式化字元串,如果使用String.format方法格式化字元串,會忽略字元串中的所有HTML標簽。為了使format方法可以格式化帶
HTML標簽的確字元,需要使用Html.formHTML方法處理字元串;

<resources>
<string name="hello_world">Welcome to <b>android</b></string>
<string name="str2">Hello,%1$s! You have <b> %2d new messages </b></string> <!--同時包含佔位符和html標簽的字元串-->
</resources>
由於需要使用Html.formHTML方法處理字元串,因此HTML標簽中的 "<" 需要使用 "<" 表示 ">" 並不需要處理
獲取字元串:

String text = String.format(getResources().getString(R.string.str2), "ly", 10);
CharSequence styledText = Html.fromHtml(text);
// 如果format的某個參數包含HTML的特殊字元,如"<","&",可以使用如下方式讀取字元串的值;
String escapedUsername = TextUtils.htmlEncode("");
String text1 = String.format(getResources().getString(R.string.str2), "ly", 20);
2.Layout資源
1、如果根節點是View,除了<requestFocus>標簽外,不能添加任何子標簽,<requestFocus>可能被添加到布局文件的任何View中,表示該標簽對應的控制項在顯示時處於焦點狀態,整個布局文件只能有一個<requestFocus>標簽
2、根節點是ViewGroup,常用的布局都是ViewGroup的子類
3、重用布局文件
如果想重用某個布局文件,可以使用<include>標簽
<include layout="@layout/xx_layout" />
如果想讓一個布局文件被另一個布局文件引用(使用<include>標簽),可以使用<merge>作為被引用布局文件的根節點,由於<merge>並不會生成任何標簽(在大量引用布局文件時不至於生成大量無用的標簽),但是xml文件必須要有一個根節點,因此<merge>所起的作用就是作為xml文件的根節點,以使xml文件在編譯時不至於出錯,可以把<merge>當成<FrameLayout>使用;

3.圖像資源
在圖像資源中可以存儲圖像文件,還可以使用xml格式的圖像資源來控制項圖像的狀態和行為;
>>1.普通圖像資源
Drawable da = getResources().getDrawable(R.drawable.xxx);

>>2.xml圖像資源
xml圖像資源其實就是在drawable目錄中指定的xml文件,此種方式可以額外指定圖像的某些屬性,如圖像拉動、排列方式;

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_launcher"
android:tileMode="repeat" >
</bitmap>
>>3.Nine-Patch圖像資源
Nine-Patch圖像資源文件必須以9.png作為文件擴展名,如abc.9.png
該圖像資源的主要作用是:防止圖像的某一部分被拉伸;確定將圖像作為背景圖的控制項中內容顯示的位置;
Android SDK本身提供了一個Draw 9-patch的工具,啟動<sdk目錄>\tools\draw9patch.bat命令啟動該工具;
可以通過此工具在png圖的四周繪制1個像素粗的直線,上邊緣和左邊緣的直線分別表示圖像在水平和垂直方向可位值的范圍。如果水平或垂直方向的某個區域不需要拉伸,則可不繪制相應的直線;右邊緣和下邊緣的直線分別表示圖像所在控制項中內容的顯示範圍,內容只在右邊緣和下邊緣繪制直線的區域顯示,表示內容顯示範圍和拉伸范圍的兩給直線有一個重要區別就是表示內容顯示範圍的直線中間不能斷開,而表示拉伸范圍的直線中間可以斷開;
Nine-Patch圖像資源與普通圖像資源引用方法相同,在引用時只寫文件名,活力.9.png;

>>4.XML Nine-Patch圖像資源
Nine-Patch圖像資源也有與其對應的xml圖像資源,使用<nine-patch>標簽來引用Nine-Patch格式的圖像,有一個設置抖動的android:dither屬性;

>>5.圖層資源
圖層資源類似於<FrameLayout>不同的是<FrameLayout>標簽中可以包含任意的控制項,而圖層資源每一層都只有是圖像,定義圖層資源必須使用<layer-list>作為資源文件的根節點,<layer-list>標簽中包含多個<item>標簽,每一個標簽表示一個圖像,最後一個<item>標簽顯示在最頂層;
默認情況下,圖像會盡量充滿顯示圖像的范圍,圖像可能會有拉伸,為了避免圖像拉伸,可以在<item>標簽中使用<bitmap>標簽引用圖像;

復制代碼
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="10dip" 底端偏移的像素
android:left="10dip" 左側偏移的像素
android:right="10dip" ...
android:top="10dip"> ...
<bitmap
android:gravity="center"
android:src="@drawable/hell" />
</item>
</layer-list>
復制代碼
某些情況下,可以使用圖層來代替<FrameLayout>

>>6.圖像狀態資源,處理控制項不同狀態下的顯示狀態

復制代碼
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bm" android:state_focused="true"></item>
<item android:drawable="@drawable/bm" android:state_pressed="true"></item>
<item android:drawable="@drawable/bm"></item>
</selector>
// android:state_focused/pressed設置為true表示當前item的drawable屬性為獲取焦點和按下時的drawable樣式
復制代碼
>>7.圖像級別(Level)資源
圖像資源狀態只能指定幾種有限的狀態,可以通過圖像級別指定更多的狀態;圖像級別是一個整數的區間,可以通過ImageView.setImageLevel或Drawable.setLevel方法切換不同狀態的圖像;圖像級別資源是xml文件,必須以<level-list>為根節點,每一個item表示一個級別區間,下面是一個xml文件;通過ImageView.setImageLevel(level),根據level所在的區間設定顯示的圖像資源,如果level不在任一區間內則清空ImageView當前圖像;

<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="2" android:minLevel="0" android:drawable="@drawable/hell" />
<item android:maxLevel="4" android:minLevel="3" android:drawable="@drawable/hell" />
</level-list>
>>8.淡入淡出(Cross-fade)資源
也是切換兩個圖像(不支持多於兩個圖像的切換),並且使這兩個圖像以淡入淡出效果進行切換,如電燈在開關時逐漸變亮或逐漸變暗;

<transition xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/hell"/>
<item android:drawable="@drawable/hell"/>
</transition>

TransitionDrawable da = ...;
// 從第一張圖片切換到第二張圖片,時間效果為1秒
da.startTransition(1000);
// 從第二張圖片切換到第一張圖片,時間效果為1秒
da.reverseTransition(1000);
>>9.嵌入(insert)圖像資源
使用場景:要顯示的圖像要求要小於裝載圖像的View(圖小於View區域),也是通過xml資源定義,只有一個節點inset。

<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/hell"
android:insetLeft="10dip" > <!--圖像距離左邊的距離,延伸-->上/下/右的距離-->
</inset>
>>10.剪切(Clip)圖像資源,使用剪切圖像資源可以只顯示圖像的一部分,如可以通過此來製作進度條;

<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:clipOrientation="horizontal" // 指定截取的方向
android:drawable="@drawable/hell" // 指定要截取的圖像
android:gravity="left" > // 指定截取的方式,在此為從左側開始截取
</clip>
ClipDrawable cd = ...;
cd.setLevel(1000);
上面ClipDrawable.setLevel(level)設置截取的圖像寬度,ClipDrawable預設了最大值10000(表示不進行截取),最小值為0(表示不顯示);

>>11. 比例(Scale)圖像資源

<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/hell"
android:scaleGravity="center" // 設置圖像顯示的位置
android:scaleHeight="70%" // 設置圖像顯示的高度
android:scaleWidth="80%" > // 設置圖像顯示的寬度
</scale>
>>12.形狀資源

復制代碼
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" > shape可以指定就矩形,oval(橢圓),line(直線),ring(圓)
<corners> 定義圓角
</corners>
<gradient
android:angle="45"
android:startColor="#000000"
android:endColor="#FFFFFF" > 定義顏色漸變,從左下角到或上角
</gradient>
<padding> 定義控制項內容到邊框的距離
</padding>
<stroke> 定義邊線
</stroke>
<solid> 定義填充
</solid>
<size> 定義大小
</size>
</shape>
復制代碼
13.菜單資源
菜單不僅可以在onCreateContextMenu或onCreateOptionsMenu方法中通過代碼創建,還可以在res/menu目錄中建立相應的菜單資源文件,並在上面兩個方法中載入菜單資源;
菜單資源文件必須以<menu>標簽作為根節點,每一個菜單項用一個<item>表示,如果要定義子菜單,可以在<item>標簽中包含<menu>標簽;如果想將多個菜單項劃為一組,可以使用<group>包含多個<item>標簽;

復制代碼
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
復制代碼
查看MenuInflater.inflate(int,Menu)

復制代碼
/**
* Inflate a menu hierarchy from the specified XML resource.
*
* @param menuRes Resource ID for an XML layout resource to load (e.g., <code>R.menu.main_activity</code>)
* @param menu The Menu to inflate into. The items and submenus will be added to this Menu.
*/
public void inflate(int menuRes, Menu menu) {
XmlResourceParser parser = null;
try {
parser = mContext.getResources().getLayout(menuRes);
AttributeSet attrs = Xml.asAttributeSet(parser);

parseMenu(parser, attrs, menu);
} catch ...finally {
if (parser != null) parser.close();
}
}
復制代碼
14.樣式與主題(style/theme)
>>1.樣式style
android中樣式和css中樣式作用是一樣的,都是用於為界面元素定義顯示風格,它是一個包含一個或者多個控制項屬性的集合。
定義樣式需要在res/values/styles.xml中進行定義,如下是一個樣式的定義:

<style name="textViewStyle">
<item name="android:textSize">22sp</item>
<item name="android:textColor">#FF0000</item>
</style>
<style name="textViewStyle1" parent="textViewStyle"></style><!-- 此樣式繼承自textViewStyle -->
<style name="textViewStyle.Livingstone"><!-- 樣式繼承的另一種寫法,但不可用此寫法繼承Android自帶的定義樣式? -->
<item name="android:textColor">#00FF00</item>
</style>
所有定義的樣式都會在R文件中自動生成一個資源ID,加一個點表示樣式繼承會生成上圖所示的資源id;

樣式的引用:

<TextView
style="@style/textViewStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="hello" />
>>2.主題Theme
主題應用於整個應用或者activity,樣式應用於具體的控制項上。主題的應用與樣式定義一樣,不同的是主題還可以設置窗口的顯示風格;主題的引用需要在清單文件中進行引用,如引用到整個應用之上就需要在Application節點中進行配置引用,而引用到單個Activity只需要在此Activity中進行配置引用;

復制代碼
<style name="Livingstonetheme"><!--此定義是一個無Title的主題-->
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">?android:windowNoTitle</item>
<!-- 問號表示引用此主題中android:windowNoTitle屬性的值 -->
<item name="android:textSize">18sp</item>
</style>
復制代碼
android系統定義了一些屬性,如android:theme="@android:style/Theme.Dialog",該主題可以讓Activity看起來像一個對話框,更多主題可以在文檔reference->android->R.style中查看。當主題裡面的樣式屬性值與樣式裡面的屬性值發生沖突的時候會顯示樣式裡面的值;

15.其它資源
在資源文件中還可以包括尺寸(dimen)、整數(integer)、布爾(bool) 、整形數組資源(integer-array)、資源數組(array)、顏色(color)

TypedArray ta = getResources().obtainTypedArray(int id); // 獲取數組資源,包括integer-array、array
Final總結:
除了res/values目錄中的資源名,其它目錄的資源都會以文件名在R類的相應子類中生成變數;而res/values中的資源會以name屬性值為變數名在R類的相應子類中生成變數;

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

為你其中提供一種解決方案:
android;msg_new_counter"22"
android;
android;20dp"
android;>.com/apk/res/android"0dp" android;
android;
android;
android;utf-8".android;/://schemas;TextView
android; /:width="shape xmlns;top|center_horizontal".com/apk/res/android" target="_blank">http.0":background="3dp":text=":layout_height="bold" android;false"
android:textColor="ring"solid android;>
android;bg_have_msg".android://schemas;wrap_content":layout_width=";2":layout_marginTop="8sp":shape="stroke android; encoding="1;
android;3dp"
android;
<:id="
android;
<

2;#ffffff":useLevel="wrap_content"?xml version=":innerRadiusRatio=":textSize="#ff0000">@+id/1"
<
android;
android:color=":layout_marginLeft="#ff0000"
android:thicknessRatio=":color=".資源文件

<?>:textStyle="/ /:innerRadius=":padding=":android=">
<

在android studio的布局預覽里顯示正常(紅底白字的圓):thickness="
android布局文件

<1dp"

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:619
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:347
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:62
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:288
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:781
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:334
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:197
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:791
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:350
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:578