日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Android沉浸式狀態(tài)欄及懸浮效果

一、概述

網(wǎng)站建設哪家好,找成都創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、微信小程序開發(fā)、集團企業(yè)網(wǎng)站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了麗江免費建站歡迎大家使用!

現(xiàn)在大多數(shù)的電商APP的詳情頁長得幾乎都差不多,幾乎都是上面一個商品的圖片,當你滑動的時候,會有Tab懸浮在上面,這樣做用戶體驗確實不錯,如果Tab滑上去,用戶可能還需要滑下來,在來點擊Tab,這樣確實很麻煩。沉浸式狀態(tài)欄那,郭霖說過谷歌并沒有給出沉浸式狀態(tài)欄這個明白,谷歌只說了沉浸式模式(Immersive Mode)。不過沉浸式狀態(tài)欄這個名字其實聽不粗,隨大眾吧,但是Android的環(huán)境并沒有IOS環(huán)境一樣特別統(tǒng)一,比如華為rom的跟小米rom的虛擬按鍵完全不一樣,所有Android開發(fā)者不容易。。。。。

二、淘寶的效果 

三、我們的效果 

只能傳2M,把我的美女都給壓失真了。。。。。。

四、實現(xiàn)類

自定義ScrollView (StickyScrollView)

StatusBarUtil //非常不錯的狀態(tài)欄工具

五、布局 

 
 
 
 
  1.  
  2. xmlns:tools="http://schemas.android.com/tools" 
  3. android:layout_width="match_parent" 
  4. android:layout_height="match_parent"> 
  5.  
  6.     android:layout_width="match_parent" 
  7.     android:layout_height="match_parent"> 
  8.  
  9.     
  10.         android:id="@+id/scrollView" 
  11.         android:layout_width="match_parent" 
  12.         android:layout_height="match_parent" 
  13.         android:focusable="true" 
  14.         android:focusableInTouchMode="true"> 
  15.  
  16.         
  17.             android:id="@+id/ll_content" 
  18.             android:layout_width="match_parent" 
  19.             android:layout_height="match_parent" 
  20.             android:orientation="vertical"> 
  21.  
  22.             
  23.                 android:layout_width="match_parent" 
  24.                 android:layout_height="500dip" 
  25.                 android:background="@mipmap/meinv"/> 
  26.  
  27.             
  28.                 android:id="@+id/title" 
  29.                 android:layout_width="match_parent" 
  30.                 android:layout_height="50dp" 
  31.                 android:gravity="center" 
  32.                 android:text="美" /> 
  33.  
  34.             
  35.                 android:layout_width="match_parent" 
  36.                 android:layout_height="50dip" 
  37.                 android:gravity="center" 
  38.                 android:text="女"/> 
  39.  
  40.             
  41.                 android:layout_width="match_parent" 
  42.                 android:layout_height="50dip" 
  43.                 android:gravity="center" 
  44.                 android:text="美"/> 
  45.             
  46.                 android:layout_width="match_parent" 
  47.                 android:layout_height="50dip" 
  48.                 android:gravity="center" 
  49.                 android:text="不"/> 
  50.             
  51.                 android:layout_width="match_parent" 
  52.                 android:layout_height="50dip" 
  53.                 android:gravity="center" 
  54.                 android:text="美"/> 
  55.  
  56.             
  57.                 android:layout_width="match_parent" 
  58.                 android:layout_height="wrap_content" 
  59.                 android:orientation="vertical" 
  60.                 android:tag="sticky"> 
  61.  
  62.                 
  63.                     android:layout_width="match_parent" 
  64.                     android:layout_height="45dp" 
  65.                     android:background="#ffffff" 
  66.                     android:orientation="horizontal"> 
  67.  
  68.                     
  69.                         android:id="@+id/infoText" 
  70.                         android:layout_width="0dp" 
  71.                         android:layout_height="match_parent" 
  72.                         android:layout_weight="1" 
  73.                         android:gravity="center" 
  74.                         android:text="美女信息" 
  75.                         android:textColor="#000000" 
  76.                         android:textSize="16dp" /> 
  77.  
  78.                     
  79.                         android:id="@+id/secondText" 
  80.                         android:layout_width="0dp" 
  81.                         android:layout_height="match_parent" 
  82.                         android:layout_weight="1" 
  83.                         android:gravity="center" 
  84.                         android:text="美女介紹" 
  85.                         android:textColor="#000000" 
  86.                         android:textSize="16dp" /> 
  87.                  
  88.              
  89.  
  90.             
  91.                 android:id="@+id/tabMainContainer" 
  92.                 android:layout_width="match_parent" 
  93.                 android:layout_height="wrap_content" 
  94.                 android:background="#ffffff" 
  95.                 android:minHeight="400dp"> 
  96.  
  97.              
  98.          
  99.      
  100.  
  101.     
  102.         android:id="@+id/ll_good_detail" 
  103.         android:layout_width="match_parent" 
  104.         android:layout_height="49dp" 
  105.         android:background="#00000000" 
  106.         android:paddingTop="@dimen/spacing_normal"> 
  107.  
  108.         
  109.             android:layout_width="wrap_content" 
  110.             android:layout_height="wrap_content" 
  111.             android:textColor="#ffffff" 
  112.             android:layout_alignParentLeft="true" 
  113.             android:layout_marginLeft="10dip" 
  114.             android:layout_centerHorizontal="true" 
  115.             android:text="返回"/> 
  116.  
  117.         
  118.             android:layout_width="wrap_content" 
  119.             android:layout_height="wrap_content" 
  120.             android:textColor="#ffffff" 
  121.             android:layout_centerInParent="true" 
  122.             android:layout_centerHorizontal="true" 
  123.             android:layout_marginLeft="10dip" 
  124.             android:text="美女"/> 
  125.  
  126.         
  127.             android:layout_width="wrap_content" 
  128.             android:layout_height="wrap_content" 
  129.             android:textColor="#ffffff" 
  130.             android:layout_alignParentRight="true" 
  131.             android:layout_marginRight="10dip" 
  132.             android:layout_centerHorizontal="true" 
  133.             android:text="分享"/> 
  134.  
  135.      
  136.  
  137.  
  138.  
  139.   

注意:我們把要懸浮的Tab設置了android:tag=”sticky”這樣的屬性

六、實現(xiàn)代碼

 
 
 
 
  1. public class MainActivity extends AppCompatActivity implements View.OnClickListener, StickyScrollView.OnScrollChangedListener { 
  2.  
  3. TextView oneTextView, twoTextView; 
  4. private StickyScrollView stickyScrollView; 
  5. private int height; 
  6. private LinearLayout llContent; 
  7. private RelativeLayout llTitle; 
  8. private FrameLayout frameLayout; 
  9. private TextView title; 
  10.  
  11. @Override 
  12. protected void onCreate(Bundle savedInstanceState) { 
  13.     super.onCreate(savedInstanceState); 
  14.     setContentView(R.layout.activity_main); 
  15.     initView(); 
  16.     initListeners(); 
  17.  
  18.  
  19. /** 
  20.  * 初始化View 
  21.  */ 
  22. private void initView() { 
  23.     stickyScrollView = (StickyScrollView) findViewById(R.id.scrollView); 
  24.     frameLayout = (FrameLayout) findViewById(R.id.tabMainContainer); 
  25.     title = (TextView) findViewById(R.id.title); 
  26.     oneTextView = (TextView) findViewById(R.id.infoText); 
  27.     llContent = (LinearLayout) findViewById(R.id.ll_content); 
  28.     llTitle = (RelativeLayout) findViewById(R.id.ll_good_detail); 
  29.     oneTextView.setOnClickListener(this); 
  30.     twoTextView = (TextView) findViewById(R.id.secondText); 
  31.     twoTextView.setOnClickListener(this); 
  32.  
  33.     stickyScrollView.setOnScrollListener(this); 
  34.     StatusBarUtil.setTranslucentForImageView(MainActivity.this, 0, title); 
  35.     FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) llTitle.getLayoutParams(); 
  36.     params.setMargins(0, getStatusHeight(), 0, 0); 
  37.     llTitle.setLayoutParams(params); 
  38.  
  39.     //默認設置一個Frg 
  40.     getSupportFragmentManager().beginTransaction().replace(R.id.tabMainContainer, Fragment.newInstance()).commit(); 
  41.  
  42. /** 
  43.  * 獲取狀態(tài)欄高度 
  44.  * @return 
  45.  */ 
  46. private int getStatusHeight() { 
  47.     int resourceId = MainActivity.this.getResources().getIdentifier("status_bar_height", "dimen", "android"); 
  48.     return getResources().getDimensionPixelSize(resourceId); 
  49.  
  50.  
  51. @Override 
  52. public void onClick(View v) { 
  53.     if (v.getId() == R.id.infoText) { 
  54.         getSupportFragmentManager().beginTransaction().replace(R.id.tabMainContainer, Fragment.newInstance()).commit(); 
  55.     } else if (v.getId() == R.id.secondText) { 
  56.         getSupportFragmentManager().beginTransaction().replace(R.id.tabMainContainer, Fragment1.newInstance()).commit(); 
  57.  
  58.     } 
  59.  
  60. private void initListeners() { 
  61.     //獲取內(nèi)容總高度 
  62.     final ViewTreeObserver vto = llContent.getViewTreeObserver(); 
  63.     vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
  64.         @Override 
  65.         public void onGlobalLayout() { 
  66.             height = llContent.getHeight(); 
  67.             //注意要移除 
  68.             llContent.getViewTreeObserver() 
  69.                     .removeGlobalOnLayoutListener(this); 
  70.  
  71.         } 
  72.     }); 
  73.  
  74.     //獲取Fragment高度 
  75.     ViewTreeObserver viewTreeObserver = frameLayout.getViewTreeObserver(); 
  76.     viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
  77.         @Override 
  78.         public void onGlobalLayout() { 
  79.             height = height - frameLayout.getHeight(); 
  80.             //注意要移除 
  81.             frameLayout.getViewTreeObserver() 
  82.                     .removeGlobalOnLayoutListener(this); 
  83.         } 
  84.     }); 
  85.  
  86.     //獲取title高度 
  87.     ViewTreeObserver viewTreeObserver1 = llTitle.getViewTreeObserver(); 
  88.     viewTreeObserver1.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
  89.         @Override 
  90.         public void onGlobalLayout() { 
  91.             height = height - llTitle.getHeight() - getStatusHeight();//計算滑動的總距離 
  92.             stickyScrollView.setStickTop(llTitle.getHeight() + getStatusHeight());//設置距離多少懸浮 
  93.             //注意要移除 
  94.             llTitle.getViewTreeObserver() 
  95.                     .removeGlobalOnLayoutListener(this); 
  96.         } 
  97.     }); 
  98.  
  99.  
  100. @Override 
  101. public void onScrollChanged(int l, int t, int oldl, int oldt) { 
  102.     if (t <= 0) { 
  103.         llTitle.setBackgroundColor(Color.argb((int) 0, 255, 255, 255)); 
  104.         StatusBarUtil.setTranslucentForImageView(MainActivity.this, 0, title); 
  105.     } else if (t > 0 && t <= height) { 
  106.         float scale = (float) t / height; 
  107.         int alpha = (int) (255 * scale); 
  108.         llTitle.setBackgroundColor(Color.argb((int) alpha, 227, 29, 26));//設置標題欄的透明度及顏色 
  109.         StatusBarUtil.setTranslucentForImageView(MainActivity.this, alpha, title);//設置狀態(tài)欄的透明度 
  110.     } else { 
  111.         llTitle.setBackgroundColor(Color.argb((int) 255, 227, 29, 26)); 
  112.         StatusBarUtil.setTranslucentForImageView(MainActivity.this, 255, title); 
  113.     } 
  114.  }  

注意:stickyScrollView.setStickTop(int height)我們通過這個方法可以設置Tab距離多高開始懸浮

我們通過監(jiān)聽ScrollView滑動距離來不斷改變我們標題欄跟狀態(tài)欄的透明度來達到效果,在這里我們計算了幾個高度(滑動距離)。最后來算出滑動總距離,根據(jù)滑動的距離跟滑動的總距離來算出透明度的數(shù)值。

StatusBarUtil.setTranslucentForImageView(MainActivity.this, 0, title);我們通過工具來實現(xiàn)圖片深入狀態(tài)欄。里面的傳的View是圖片下面的View。

六、總結

效果倒是不錯,美女也不錯、但是在Android4.4之前根本就沒有沉浸式這個東西,大家可以下載源碼來研究。自己動手實現(xiàn)一遍記得比較清楚。工作了。太忙了。最后感謝一下dota群的高叔(博客地址不知道)提供思路。


網(wǎng)頁名稱:Android沉浸式狀態(tài)欄及懸浮效果
鏈接URL:http://www.5511xx.com/article/ccoihgc.html