Android實(shí)現(xiàn)圖片滾動效果
更新時(shí)間:2020年09月17日 14:56:52 作者:堯堯?qū)氊?
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)圖片滾動效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
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ò)圖片加載+滾動翻頁的例子(圖片能緩存,圖片不錯(cuò)亂)
相關(guān)文章
Android編程讀取Assets所有文件(遍歷每一個(gè)文件夾)并存入sdcard的方法
這篇文章主要介紹了Android編程讀取Assets所有文件(遍歷每一個(gè)文件夾)并存入sdcard的方法,涉及Android針對文件與目錄的遍歷及I/O操作相關(guān)技巧,需要的朋友可以參考下2016-02-02android列表控件實(shí)現(xiàn)展開、收縮功能
這篇文章主要為大家詳細(xì)介紹了android支持展開/收縮功能的列表控件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-11-11Android編程實(shí)現(xiàn)懸浮窗獲取并顯示當(dāng)前內(nèi)存使用量的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)懸浮窗獲取并顯示當(dāng)前內(nèi)存使用量的方法,涉及Android針對窗口及內(nèi)存的相關(guān)操作技巧,需要的朋友可以參考下2017-07-07Android 自定義View實(shí)現(xiàn)抽屜效果
這篇文章主要介紹了Android 自定義View實(shí)現(xiàn)抽屜效果的相關(guān)資料,需要的朋友可以參考下2017-05-05