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

首頁 > 系統 > Android > 正文

Android仿淘寶頭條基于TextView實現上下滾動通知效果

2019-12-12 03:25:40
字體:
來源:轉載
供稿:網友

最近有個項目需要實現通知欄的上下滾動效果,仿淘寶頭條的那種。

我從網上看了一些代碼,把完整的效果做了出來。如圖所示:

具體代碼片段如下:

1.在res文件夾下新建anmin文件夾,在這個文件夾里創建兩個文件

(1).anim_marquee_in.xml進入時動畫

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="1500" android:fromYDelta="100%p" android:toYDelta="0"> </translate> </set> 

(2).anim_marquee_out.xml退出時動畫

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate  android:duration="1500"  android:fromYDelta="0"  android:toYDelta="-100%p"> </translate> </set> 

2.activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:id="@+id/activity_main"  android:layout_width="match_parent"  android:layout_height="match_parent"  tools:context="com.spore.marqueeview.MainActivity" >  <ViewFlipper   android:id="@+id/marquee_view"   android:layout_width="match_parent"   android:layout_height="wrap_content"   android:autoStart="true"   android:background="#fff"   android:flipInterval="2500"   android:inAnimation="@anim/anim_marquee_in"   android:outAnimation="@anim/anim_marquee_out" >  </ViewFlipper> </RelativeLayout> 

3.noticelayout.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:orientation="horizontal" >  <ImageView   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:padding="5dp"   android:src="@drawable/icon_home_notice" />  <TextView   android:layout_width="match_parent"   android:layout_height="match_parent"   android:gravity="center_vertical"   android:paddingLeft="10dp"   android:singleLine="true"   android:text="[2017-02-28 08:00]通知:上午九點整開會!"   android:textSize="18sp" /> </LinearLayout> 

4.MainActivity.java

package com.iponkan.textviewupdown; import com.example.textviewupdown.R; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.ViewFlipper; public class MainActivity extends Activity {  @Override  protected void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   setContentView(R.layout.activity_main);   // 為ViewFlipper添加廣告條   ViewFlipper vf = (ViewFlipper) findViewById(R.id.marquee_view);   vf.addView(View.inflate(this, R.layout.noticelayout, null));   vf.addView(View.inflate(this, R.layout.noticelayout, null));   vf.addView(View.inflate(this, R.layout.noticelayout, null));  }  @Override  public boolean onCreateOptionsMenu(Menu menu) {   // Inflate the menu; this adds items to the action bar if it is present.   getMenuInflater().inflate(R.menu.main, menu);   return true;  } } 

以上所述是小編給大家介紹的Android仿淘寶頭條基于TextView實現上下滾動通知效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吉木萨尔县| 延吉市| 耒阳市| 台东市| 德化县| 文山县| 德安县| 囊谦县| 芜湖县| 鄂州市| 德惠市| 孝义市| 托克托县| 宾阳县| 通海县| 贺兰县| 弥勒县| 和政县| 商南县| 巧家县| 永新县| 怀安县| 喀喇沁旗| 淳化县| 南乐县| 讷河市| 淳化县| 涡阳县| 元江| 新密市| 棋牌| 平乐县| 峨边| 南京市| 黔江区| 高雄县| 嵩明县| 米脂县| 黑水县| 湘乡市| 巴彦淖尔市|