導航:首頁 > 操作系統 > android滾動漸變

android滾動漸變

發布時間:2022-06-17 21:48:12

『壹』 怎麼在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>

『貳』 如何通過android實現alpha漸變動畫效果

Android動畫分為四種:alpha(漸變透明度),scale(漸變尺寸伸縮),translate(畫面轉換位置移動),rotate(畫面轉移旋轉);今天先寫第一個動畫alpha。
動畫效果有兩種實現:
一、在xml中定義:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 透明度控制動畫效果 alpha
浮點型值:
fromAlpha 屬性為動畫起始時透明度
toAlpha 屬性為動畫結束時透明度
說明:
0.0表示完全透明
1.0表示完全不透明
以上值取0.0-1.0之間的float數據類型的數字

長整型值:
ration 屬性為動畫持續時間
說明:
時間以毫秒為單位
-->

<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:ration="5000"
/>

</set>
二、在頁面Activity中聲明:
Animation animation = new AlphaAnimation(0.1f, 1.0f);
animation.setDuration(5000);

完成動畫漸變透明度的參數設定後,我們就要開始在應用中使用它:
public class SplashActivity extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);

View view = View.inflate(SplashActivity.this, R.layout.welcome, null);
setContentView(view);
//動畫效果參數直接定義
Animation animation = new AlphaAnimation(0.1f, 1.0f);
animation.setDuration(5000);

//動畫效果從XMl文件中定義
// Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
view.setAnimation(animation);
}
}
這樣我們就完成了預定的動畫效果,但是我們的最終目的是動畫效果完畢以後跳轉到相應的頁面,所以我們對動畫添加了監聽:
animation.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Intent intent = new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
}
});
這樣的話,我們在動畫的持續時間中預載入我們的資源,當動畫結束以後跳轉到我們的主頁面;
詳細步驟和完整源碼可以參考:http://www.cnblogs.com/sishuiliuyun/p/3167581.html

『叄』 在android中怎麼至上而下漸變

這個是輸出一層顏色漸變的效果,而你的是多層的,做法一樣,弄幾個小的的三角形同樣的畫法畫到上面。而顏色的值是不可能是線性的值,你只能自己定義每層三角形的顏色,這個是你要做的。 這個我直接用NDK自帶的HELLO-GL2給你弄的,就設置下三角形

『肆』 android 怎麼在輪播時實現多種動畫效果,如第一張到第二張漸變,第二張到第三張旋轉

Android系統自帶的一個多頁面管理控制項,它可以實現子界面的自動切換:

首先 需要為ViewFlipper加入View

(1) 靜態導入:在layout布局文件中直接導入

(2) 動態導入:addView()方法

ViewPlipper常用方法:

setInAnimation:設置View進入屏幕時候使用的動畫

setOutAnimation:設置View退出屏幕時候使用的動畫

showNext:調用該函數來顯示ViewFlipper裡面的下一個View

showPrevious:調用該函數來顯示ViewFlipper裡面的上一個View

setFlipInterval:設置View之間切換的時間間隔

startFlipping使用上面設置的時間間隔來開始切換所有的View,切換會循環進行

stopFlipping:停止View切換

講了這么多,那麼我們今天要實現的是什麼呢?

(1) 利用ViewFlipper實現圖片的輪播

(2) 支持手勢滑動的ViewFlipper

我們需要先准備幾張圖片:把圖片放進drawable中

創建兩個動畫:在res下面新建一個folder裡面新建兩個xml:

『伍』 android屬性動畫怎麼漸變

3.0以前,android支持兩種動畫模式,tween animation,frame animation,在android3.0中又引入了一個新的動畫系統:property animation,這三種動畫模式在SDK中被稱為property animation,view animation,drawable animation。?
1. View Animation(Tween Animation)
View Animation(Tween Animation):補間動畫,給出兩個關鍵幀,通過一些演算法將給定屬性值在給定的時間內在兩個關鍵幀間漸變。
View animation只能應用於View對象,而且只支持一部分屬性,如支持縮放旋轉而不支持背景顏色的改變。
而且對於View animation,它只是改變了View對象繪制的位置,而沒有改變View對象本身,比如,你有一個Button,坐標 (100,100),Width:200,Height:50,而你有一個動畫使其變為Width:100,Height:100,你會發現動畫過程中觸 發按鈕點擊的區域仍是(100,100)-(300,150)。
View Animation就是一系列View形狀的變換,如大小的縮放,透明度的改變,位置的改變,動畫的定義既可以用代碼定義也可以用XML定義,當然,建議用XML定義。
可以給一個View同時設置多個動畫,比如從透明至不透明的淡入效果,與從小到大的放大效果,這些動畫可以同時進行,也可以在一個完成之後開始另一個。
用XML定義的動畫放在/res/anim/文件夾內,XML文件的根元素可以 為<alpha>,<scale>,<translate>,<rotate>,interpolator 元素或<set>(表示以上幾個動畫的集合,set可以嵌套)。默認情況下,所有動畫是同時進行的,可以通過startOffset屬性設置 各個動畫的開始偏移(開始時間)來達到動畫順序播放的效果。
可以通過設置interpolator屬性改變動畫漸變的方式,如AccelerateInterpolator,開始時慢,然後逐漸加快。默認為。

『陸』 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>

『柒』 android控制項背景顏色動態隨機漸變

這個你只能使用shape來完成。因為是點擊後隨機變,不能使用xml寫死的那種,你得用java代碼來生成和配置GradientDrawable,設置不同的color.如果不會用,可以參照:

『捌』 android漸變設置佔比

比較簡單的一種方式實現顏色漸變,我們通過定製一個對應的shape文件,配置其屬性之後,直接作為android:background賦值給對應的View即可。
1.創建XML文件
在你的drawable文件夾下創建shape資源:
shape_gradient.xml文件代碼如下:
android:endColor="@color/colorPrimary"
android:startColor="@color/colorAccent" />
解釋一下各個層級的標簽:
[shape] 根標簽,聲明一個shape
[gradient] 聲明該shape的屬性-漸變色,除此外還有其他屬性如corners、stroke、size等等
[android:angle]漸變色的角度,舉例來說,0代表從上至下顏色漸變;45代表從左至右顏色漸變;90代表從下至上顏色漸變…
[android:startColor&android:endColor] 很好理解,漸變開始的顏色和漸變結束時的顏色(從什麼顏色變到什麼顏色)
2.將漸變色賦予對應的View
直接放入MainActivity的layout文件中

『玖』 android顏色漸變如何實現從四周往中心漸變 或者從中心往四周漸變 都行,不是 從左往右

android 顏色漸變是指通知xml或者java代碼,設置相關參數,是界面的某個指定的視圖顯示成從開始位置的顏色,逐漸過度到結尾位置的顏色的技術。

android顏色漸變的分類有:

LinearGradient線性漸變

RadialGradient鏡像漸變

SweepGradient角度漸變


一、LinearGradient線性漸變
顧名思義,是只顏色在一個直線方向上逐漸改變。

文件代碼:

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

<gradient
android:endColor="#0000FF"
android:startColor="#FF0000"
android:type="linear"/>

</shape>

效果:

閱讀全文

與android滾動漸變相關的資料

熱點內容
android獲得當前activity 瀏覽:829
python入門迷宮 瀏覽:69
Python打折代碼不含商品 瀏覽:220
把多個Word合成一個pdf 瀏覽:356
aes演算法描述 瀏覽:899
新手機壓縮包在哪 瀏覽:781
java抽獎程序源碼 瀏覽:700
汽車壓縮機又叫 瀏覽:95
android讀取data文件 瀏覽:874
紅旗智聯app怎麼跟h5車子連接 瀏覽:139
材料化學pdf 瀏覽:114
伺服器機房都有什麼東西 瀏覽:370
最近長陰短柱量能副圖指標源碼 瀏覽:647
python字元串去除後四位 瀏覽:167
捷速pdf編輯器破解版 瀏覽:725
大帶寬伺服器怎麼租 瀏覽:299
籃球程序員單身難嗎 瀏覽:877
一接到命令就 瀏覽:488
挖幣伺服器是什麼 瀏覽:524
攜帶型u盤加密 瀏覽:464