欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android圖片處理教程之全景查看效果實(shí)現(xiàn)

 更新時(shí)間:2018年06月11日 11:29:07   作者:CMusketeer  
這篇文章主要給大家介紹了關(guān)于Android圖片處理教程之全景查看效果實(shí)現(xiàn)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

前言

在玩頭條的時(shí)候,現(xiàn)在我們會(huì)發(fā)現(xiàn)有很多的全景圖的廣告這樣快看起來(lái)非常的酷。今天就來(lái)說(shuō)說(shuō)這個(gè)小效果的實(shí)現(xiàn)

PS:Android對(duì)于圖片處理這塊資源還是挺多的,之前用OpenGL制作圖片的全景效果,耗時(shí)耗力,而且只能點(diǎn)擊進(jìn)去后看到,但是效果是非常的號(hào),今天所寫(xiě)的是編寫(xiě)好的一個(gè)圖片控件,只要拿來(lái)用就可以了。效果不是那么好,處理的之后就是一張圖片截取中間部分放大再顯示在屏幕中間,通過(guò)擺動(dòng)手機(jī)查看被遮擋部分

如圖:一開(kāi)始圖片是這樣的

上面就是效果圖了

實(shí)現(xiàn)方法如下

1:添加依賴(lài)

//全景圖片
 compile 'com.gjiazhe:PanoramaImageView:1.0'

2:使用控件

<com.gjiazhe.panoramaimageview.PanoramaImageView
  android:id="@+id/panorama_image_view"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:src="@drawable/timg"
  app:piv_enablePanoramaMode="true"
  app:piv_show_scrollbar="true"
  app:piv_invertScrollDirection="false" />

布局的根目錄一定要加上

 xmlns:app=http://schemas.android.com/apk/res-auto

這里面有三個(gè)屬性(其中三個(gè))

一個(gè)是app:piv_enablePanoramaMode,使用全景效果模式,app:piv_show_scrollbar滾動(dòng)條顯示,app:piv_invertScrollDirection顛倒?jié)L動(dòng)方向,不同的值就會(huì)呈現(xiàn)不同的效果。

3:注冊(cè)GyroscopeObserver

在使用PanoramaImageView的Activity或Fragment中,您應(yīng)該在onResume()中注冊(cè)GyroscopeObserver,并記得在onPause()中注銷(xiāo)它。

public class MyActivity extends AppCompatActivity {
 
 private GyroscopeObserver gyroscopeObserver;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  // Initialize GyroscopeObserver.
  gyroscopeObserver = new GyroscopeObserver();
  // Set the maximum radian the device should rotate to show image's bounds.
  // It should be set between 0 and π/2.
  // The default value is π/9.
   gyroscopeObserver.setMaxRotateRadian(Math.PI/9);

  PanoramaImageView panoramaImageView = (PanoramaImageView) findViewById(R.id.panorama_image_view);
  // Set GyroscopeObserver for PanoramaImageView.
  panoramaImageView.setGyroscopeObserver(gyroscopeObserver);
 }

 @Override
 protected void onResume() {
  super.onResume();
  // Register GyroscopeObserver.
  gyroscopeObserver.register(this);
 }

 @Override
 protected void onPause() {
  super.onPause();
  // Unregister GyroscopeObserver.
  gyroscopeObserver.unregister();
 }
}

設(shè)置OnPanoramaScrollListener以觀察滾動(dòng)狀態(tài) 如果要在圖像滾動(dòng)時(shí)獲得回調(diào),PanoramaImageView需要設(shè)置OnPanoramaScrollListener。

panoramaImageView.setOnPanoramaScrollListener(new PanoramaImageView.OnPanoramaScrollListener() {
 @Override
 public void onScrolled(PanoramaImageView view, float offsetProgress) {
  // Do something here.
  // The offsetProgress range from -1 to 1, indicating the image scrolls
  // from left(top) to right(bottom).
 }
});

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

最新評(píng)論