最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android仿淘寶頭條基于TextView實(shí)現(xiàn)上下滾動通知效果

 更新時間:2017年03月10日 09:52:37   作者:艾妮旭  
這篇文章主要介紹了Android TextView實(shí)現(xiàn)上下滾動通知效果,需要的朋友可以參考下

最近有個項(xiàng)目需要實(shí)現(xiàn)通知欄的上下滾動效果,仿淘寶頭條的那種。

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

具體代碼片段如下:

1.在res文件夾下新建anmin文件夾,在這個文件夾里創(chuàng)建兩個文件

(1).anim_marquee_in.xml進(jìn)入時動畫

<?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]通知:上午九點(diǎn)整開會!" 
  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實(shí)現(xiàn)上下滾動通知效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論

昌吉市| 墨竹工卡县| 大方县| 柘城县| 铁岭县| 长宁县| 漯河市| 海安县| 兴文县| 剑河县| 石林| 鹰潭市| 宁陕县| 金华市| 蓬溪县| 松桃| 利川市| 涞水县| 富阳市| 深圳市| 墨玉县| 海城市| 贵州省| 织金县| 马鞍山市| 东莞市| 靖西县| 宁津县| 成武县| 邯郸市| 昌江| 波密县| 丹巴县| 清丰县| 云南省| 锡林浩特市| 南雄市| 东丽区| 瓮安县| 宁河县| 太谷县|