亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

ViewFlipper的使用,顯示圖片左右滑動效果

系統 1889 0

1.簡介

????????? ViewFlipper extends ViewAnimator,Simple ViewAnimator that will animate between two or more views that have been added to it. Only one child is shown at a time. If requested, can automatically flip between each child at a regular interval。

?????????? 簡單的ViewAnimator 可以在兩個或兩個以上的視圖間實現動畫效果,但是一次只能顯示一個子類。如果設置的話,子類可以按照一定規律來顯示。

?

2. 具體使用

?邊上代碼邊解釋

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent" android:background="#ffffff">
<!-- 滑動翻頁顯示 -->
	<ViewFlipper
		android:orientation="vertical" android:id="@+id/ViewFlipper"
		android:layout_width="fill_parent" android:layout_height="75dip"
		android:background="@drawable/gradient_dark_purple">

		<!-- (0) Loading -->
		<LinearLayout android:orientation="vertical"
			android:layout_width="fill_parent" android:layout_height="fill_parent"
			android:layout_marginLeft="15dip" android:gravity="left|center_vertical">
			<com.teleca.jamendo.widget.ProgressBar
				android:id="@+id/ProgressBar" android:layout_width="wrap_content"
				android:layout_height="wrap_content">
			</com.teleca.jamendo.widget.ProgressBar>
		</LinearLayout>

		<!-- (1) Gallery -->
		<LinearLayout android:orientation="vertical"
			android:layout_width="fill_parent" android:layout_height="fill_parent"
			android:gravity="center">
			<Gallery android:id="@+id/Gallery" android:layout_width="fill_parent"
				android:layout_height="wrap_content" android:spacing="0px" />
		</LinearLayout>

		<!-- (2) Failure -->
		<LinearLayout android:orientation="vertical"
			android:layout_width="fill_parent" android:layout_height="fill_parent"
			android:layout_marginLeft="15dip" android:gravity="left|center_vertical">
			<com.teleca.jamendo.widget.FailureBar
				android:id="@+id/FailureBar" android:layout_width="wrap_content"
				android:layout_height="wrap_content">
			</com.teleca.jamendo.widget.FailureBar>
		</LinearLayout>
	</ViewFlipper>
</LinearLayout>
  

?在viewflipper中有三個線性布局,分別為初始加載和加載后以及加載失敗。當我們在activity中這個viewflipper實例化時,我們打印

    mViewFlipper.getDisplayedChild()
  

?

會得到3。說明三個linnerlayout為她的子類。同時為了怕給主線程增加負擔,我們采用異步實現。

??

    private class NewsTask extends AsyncTask<Void, WSError, Album[]> {

		@Override
		public void onPreExecute() {
			mViewFlipper.setDisplayedChild(0);
			
			System.out.println("子類數目----"+mViewFlipper.getChildCount()+" "+mViewFlipper.getDisplayedChild());
			
			mProgressBar.setText(R.string.loading_news);
			super.onPreExecute();
		}

		@Override
		public Album[] doInBackground(Void... params) {
			JamendoGet2Api server = new JamendoGet2ApiImpl();
			Album[] albums = null;
			try {
				albums = server.getPopularAlbumsWeek();
			} catch (JSONException e) {
				e.printStackTrace();
			} catch (WSError e){
				publishProgress(e);
			}
			System.out.println("doInBackground"+mViewFlipper.getDisplayedChild());
			return albums;
		}

		@Override
		public void onPostExecute(Album[] albums) {

			if(albums != null && albums.length > 0){
				mViewFlipper.setDisplayedChild(1);
				ImageAdapter albumsAdapter = new ImageAdapter(HomeActivity.this);
				albumsAdapter.setList(albums);
				mGallery.setAdapter(albumsAdapter);
				mGallery.setOnItemClickListener(mGalleryListener);
				mGallery.setSelection(albums.length/2, true); // animate to center

			} else {
				mViewFlipper.setDisplayedChild(2);
				mFailureBar.setOnRetryListener(new OnClickListener(){

					@Override
					public void onClick(View v) {
						new NewsTask().execute((Void)null);
					}

				});
				mFailureBar.setText(R.string.connection_fail);
			}
System.out.println("onPostExecute"+mViewFlipper.getDisplayedChild());
			super.onPostExecute(albums);
		}

  

?

這個類實現了我們的操作。

?在oncreate()中使用

    new NewsTask().execute((Void)null);
  

?

調用異步操作。

接下來,我們只講解子類1,即加載成功后的顯示效果。

如圖:


ViewFlipper的使用,顯示圖片左右滑動效果
?在以上代碼中,if(albums != null && albums.length > 0){
mViewFlipper.setDisplayedChild(1);//設置顯示第一面即成功加載后的效果
ImageAdapter albumsAdapter = new ImageAdapter(HomeActivity.this);//自定義了一個adpter,來組織顯示樣式
??? albumsAdapter.setList(albums);//將數據放入其中,那么albums?自然是個bean了。里面定義了albums?的各種屬性,如發行時間,專輯名等。
??? mGallery.setAdapter(albumsAdapter);//給畫布設置適配器,使畫布顯示出效果來。
mGallery.setOnItemClickListener(mGalleryListener);//添加監聽,實現對指定專輯的使用
??? mGallery.setSelection(albums.length/2, true);} //設置默認顯示區域

?

?

ViewFlipper的使用,顯示圖片左右滑動效果


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 不卡一级aaa全黄毛片 | 奇米四色视频 | 毛片免费视频播放 | 青青成人| 中文字幕福利 | 超级97碰碰碰碰久久久久最新 | 久久优 | 亚洲视频精品 | 午夜激情婷婷 | 欧美日本视频一区 | 欧美国产日韩在线播放 | 99热久久这里只有精品 | 在线亚洲精品国产成人二区 | 成人性色生活片免费看爆迷你毛片 | 午夜国产精品久久影院 | 99久久国产亚洲综合精品 | 国产精品一区不卡 | 97精品视频共享总站 | 天天艹天天操 | 天天操天天摸天天舔 | 99久久国产综合精品五月天 | 欧美肥老太婆交 | 美女视频91 | 日韩精品视频在线观看免费 | 精品影视| 色图综合网 | 91亚色视频在线观看 | 天天色色网 | 成人a毛片高清视频 | 久久中文字幕综合不卡一二区 | 爱爱免费视屏 | 亚洲视频在线观看不卡 | 国产h版大片在线播放 | 99热这里只有精品2 99热这里只有精品3 | 最近中文字幕无免费视频 | 精品久久洲久久久久护士 | 黄色免费毛片 | 久草在线精品视频 | 国产精品9999久久久久 | 欧美日本亚洲国产一区二区 | 久久社区|