国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android中創(chuàng)建類似Instagram的漸變背景效果

2019-12-12 01:30:47
字體:
供稿:網(wǎng)友

我在我最近的項(xiàng)目用到這個(gè)效果,給大家分享下

https://github.com/zhaoweihaoChina/hnuplus

1. 在drawable文件夾創(chuàng)建一些漸變顏色的資源

color1.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">  <gradient    android:startColor="#614385"    android:endColor="#516395"    android:angle="0"/></shape>

color2.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">  <gradient    android:startColor="#5f2c82"    android:endColor="#49a09d"    android:angle="45"/></shape>

color3.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">  <gradient    android:startColor="#4776E6"    android:endColor="#8E54E9"    android:angle="90"/></shape>

color4.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">  <gradient    android:startColor="#7141e2"    android:endColor="#d46cb3"    android:angle="135"/></shape>

2. 創(chuàng)建一個(gè)用到上面創(chuàng)建的漸變色的動(dòng)畫序列,命名為animation_list.xml,放進(jìn)去drawable文件夾

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android">  <item    android:drawable="@drawable/color1"    android:duration="10000" />  <item    android:drawable="@drawable/color2"    android:duration="10000" />  <item    android:drawable="@drawable/color3"    android:duration="10000" />  <item    android:drawable="@drawable/color4"    android:duration="10000" /></animation-list>

3. 將上面已經(jīng)創(chuàng)建好的動(dòng)畫序列應(yīng)用到你layout的背景頂層的view中

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"  android:background="@drawable/animation_list"  android:id="@+id/container">  <!-- Child Views --></LinearLayout>

4.在你的activity中用AnimationDrawable去實(shí)現(xiàn)過渡效果

LinearLayout container = (LinearLayout) findViewById(R.id.container);AnimationDrawable anim = (AnimationDrawable) container.getBackground();anim.setEnterFadeDuration(6000);anim.setExitFadeDuration(2000);// 開始播放動(dòng)畫:在onResume方法中開始播放漸變動(dòng)畫@Overrideprotected void onResume() {  super.onResume();  if (anim != null && !anim.isRunning())    anim.start();}   // 停止播放動(dòng)畫:在onPause方法中停止播放漸變動(dòng)畫@Overrideprotected void onPause() {  super.onPause();  if (anim != null && anim.isRunning())    anim.stop();}

將狀態(tài)欄設(shè)置透明(去除狀態(tài)欄)

values/styles.xml

<resources>   <style name="Theme.AppTheme.TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar" /> </resources>

values-v19/styles.xml

<resources>   <style name="Theme.AppTheme.TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar">     <item name="android:windowTranslucentStatus">true</item>   </style> </resources>

values-v21/styles.xml

<resources>   <style name="Theme.AppTheme.TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar">     <item name="android:statusBarColor">@android:color/transparent</item>   </style> </resources>

values-v23/styles.xml

<resources>   <style name="Theme.AppTheme.TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar">     <item name="android:statusBarColor">@android:color/transparent</item>     <item name="android:windowLightStatusBar">true</item>   </style> </resources>
public class MainActivity extends AppCompatActivity {   @Override   protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);      // 加入下面的代碼    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {       findViewById(android.R.id.content).setSystemUiVisibility(           View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);     }      setContentView(R.layout.activity_splash);   } } <activity   android:name=".MainActivity"  android:theme="@style/Theme.AppTheme.TranslucentStatusBar" />

總結(jié)

以上所述是小編給大家介紹的Android中創(chuàng)建類似Instagram的漸變背景效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對武林網(wǎng)網(wǎng)站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 苍梧县| 卓资县| 荣成市| 化州市| 西畴县| 祁阳县| 太康县| 金平| 湖州市| 西和县| 天门市| 筠连县| 南涧| 江阴市| 临猗县| 伊宁县| 朝阳市| 镇宁| 玉田县| 揭阳市| 偏关县| 周口市| 隆昌县| 西和县| 调兵山市| 富民县| 都昌县| 扎赉特旗| 新余市| 古田县| 佛冈县| 郓城县| 呼玛县| 高阳县| 尼木县| 资兴市| 鹤岗市| 河北区| 沂水县| 绵阳市| 江达县|