Android實(shí)現(xiàn)圖片滾動效果
Android開發(fā)圖片滾動效果,供大家參考,具體內(nèi)容如下
效果圖:

設(shè)置適配來設(shè)置圖片位置大小
package com.example.gallary;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter {
private Context mContext; // 圖片數(shù)組源
private Integer[] imgs = { R.drawable.img1, R.drawable.img2, R.drawable.img3, R.drawable.img4, R.drawable.img5, R.drawable.img6, R.drawable.img7};
public ImageAdapter(Context c) { mContext = c; }
@Override
public int getCount() { return imgs.length; } // 獲取圖片位置
@Override
public Object getItem(int position) { return imgs[position]; } // 獲取圖片ID
@Override
public long getItemId(int position) { return position; }
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageview = new ImageView(mContext);
imageview.setImageResource(imgs[position]);
imageview.setLayoutParams(new Gallery.LayoutParams(240, 200)); // 設(shè)置布局 圖片120×120顯示
imageview.setScaleType(ImageView.ScaleType.CENTER); // 設(shè)置顯示比例類型(不縮放)
return imageview; }
}
main添加圖片資源
package com.example.gallary;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this)); // gallery添加ImageAdapter圖片資源
}
}
布局
<TextView android:id="@+id/tv" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:layout_gravity="center" android:layout_marginTop="50dip" android:textColor="#ffff0000" android:textSize="30sp" android:text="滾動圖片"/> <Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dip" android:layout_below="@id/tv" />
drawable放置圖片資源

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android高級圖片滾動控件實(shí)現(xiàn)3D版圖片輪播器
- Android使用自定義屬性實(shí)現(xiàn)圖片自動播放滾動的功能
- Android實(shí)現(xiàn)圖片滾動和頁簽控件功能的實(shí)現(xiàn)代碼
- Android使用Recyclerview實(shí)現(xiàn)圖片水平自動循環(huán)滾動效果
- Android_RecyclerView實(shí)現(xiàn)上下滾動廣告條實(shí)例(帶圖片)
- Android組件Glide實(shí)現(xiàn)圖片平滑滾動效果
- Android仿淘寶商品瀏覽界面圖片滾動效果
- Android程序開發(fā)ListView+Json+異步網(wǎng)絡(luò)圖片加載+滾動翻頁的例子(圖片能緩存,圖片不錯亂)
相關(guān)文章
Android實(shí)現(xiàn)發(fā)送短信功能實(shí)例詳解
這篇文章主要介紹了Android實(shí)現(xiàn)發(fā)送短信功能的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android實(shí)現(xiàn)發(fā)送短信的原理、步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-02-02
Android對EditTex的圖片實(shí)現(xiàn)監(jiān)聽
這篇文章主要為大家詳細(xì)介紹了Android如何對EditTex的圖片實(shí)現(xiàn)監(jiān)聽,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10
Android ScrollView的頂部下拉和底部上拉回彈效果
本篇文章主要介紹了Android ScrollView的頂部下拉和底部上拉回彈效果,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05
Android 文件存儲與SharedPreferences存儲方式詳解用法
SharedPreferences是安卓平臺上一個(gè)輕量級的存儲類,用來保存應(yīng)用的一些常用配置,比如Activity狀態(tài),Activity暫停時(shí),將此activity的狀態(tài)保存到SharedPereferences中;當(dāng)Activity重載,系統(tǒng)回調(diào)方法onSaveInstanceState時(shí),再從SharedPreferences中將值取出2021-10-10
Android中ListView下拉刷新的實(shí)現(xiàn)方法
這篇文章主要為大家詳細(xì)介紹了Android中ListView下拉刷新的實(shí)現(xiàn)方法,感興趣的小伙伴們可以參考一下2016-03-03
Android MarginDesign控件TabLayout導(dǎo)航欄使用詳解
這篇文章主要為大家詳細(xì)介紹了Android MarginDesign控件TabLayout導(dǎo)航欄使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01

