Android實(shí)現(xiàn)漂亮的Gallery畫(huà)廊
本文實(shí)例為大家分享了Android實(shí)現(xiàn)Gallery畫(huà)廊的具體代碼,供大家參考,具體內(nèi)容如下
僅是實(shí)現(xiàn)基本功能,頁(yè)面粗糙請(qǐng)見(jiàn)諒
圖片下標(biāo)0開(kāi)始

activity_main.xml頁(yè)面:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.gallery.MainActivity"> <Gallery android:id="@+id/galPicture" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> </RelativeLayout>
GalleryAdapter.java頁(yè)面:
package com.example.gallery;
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 GalleryAdapter extends BaseAdapter {
private Context mContext;
int[] images = {R.mipmap.apple, R.mipmap.banana, R.mipmap.bicycle, R.mipmap.chair,R.mipmap.chopsticks, R.mipmap.dog, R.mipmap.fish, R.mipmap.pear}; //本地圖片
public GalleryAdapter (Context context) {
this.mContext = context;
}
@Override
public int getCount() {
return images.length;
}
@Override
public Object getItem(int i) {
return i;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ImageView image = new ImageView(mContext);
image.setImageResource(images[i]); //設(shè)置圖片
image.setAdjustViewBounds(true); //是否調(diào)整邊框
image.setLayoutParams(new Gallery.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return image;
}
}
MainActivity.java頁(yè)面:
package com.example.gallery;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
GalleryAdapter galleryAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Gallery galPicture = findViewById(R.id.galPicture);
galleryAdapter = new GalleryAdapter(MainActivity.this);
galPicture.setAdapter(galleryAdapter);
//相應(yīng)的點(diǎn)擊事件
galPicture.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(MainActivity.this, "圖片" + i, Toast.LENGTH_LONG).show();
}
});
}
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android中Gallery和ImageSwitcher的使用實(shí)例
- Android TV開(kāi)發(fā):實(shí)現(xiàn)3D仿Gallery效果的實(shí)例代碼
- Android自定義Gallery控件實(shí)現(xiàn)3D圖片瀏覽器
- Android開(kāi)發(fā)中畫(huà)廊視圖Gallery的兩種使用方法分析
- Android高級(jí)組件Gallery畫(huà)廊視圖使用方法詳解
- Android UI控件之Gallery實(shí)現(xiàn)拖動(dòng)式圖片瀏覽效果
- Android 使用自定義RecyclerView控件實(shí)現(xiàn)Gallery效果
- Android開(kāi)發(fā)實(shí)現(xiàn)Gallery畫(huà)廊效果的方法
- Android使用gallery和imageSwitch制作可左右循環(huán)滑動(dòng)的圖片瀏覽器
- Android之Gallery使用例子
- Android使用Gallery實(shí)現(xiàn)照片拖動(dòng)的特效
相關(guān)文章
Android利用Flutter?path繪制粽子的示例代碼
端午將至,作為中華民族的非常重要的傳統(tǒng)節(jié)日,粽子那是必不可少的。今天跟隨本篇文章用Flutter?path畫(huà)一個(gè)會(huì)科普節(jié)日的的粽子吧2022-05-05
Android7.0 工具類(lèi):DiffUtil詳解
這篇文章主要介紹了Android7.0 工具類(lèi):DiffUtil的相關(guān)資料,并附實(shí)例代碼,和實(shí)現(xiàn)效果圖,需要的朋友可以參考下2016-09-09
Android媒體通知欄多系統(tǒng)適配實(shí)例講解
對(duì)于Android來(lái)說(shuō)其中一項(xiàng)很方便的操作便是下拉菜單,下拉菜單欄可以快捷打開(kāi)某項(xiàng)設(shè)置,這篇文章主要給大家介紹了關(guān)于Android通知欄增加快捷開(kāi)關(guān)的功能實(shí)現(xiàn),需要的朋友可以參考下2023-04-04
Android LayoutInflater中 Inflate()方法應(yīng)用
本文主要介紹Android 中Inflate 方法的用法, 在開(kāi)發(fā)Android應(yīng)用過(guò)程中,可以在程序中應(yīng)用 Inflate()方法加載新布局,希望能幫助有需要的朋友2016-07-07
Android App中使用Pull解析XML格式數(shù)據(jù)的使用示例
這篇文章主要介紹了Android App中使用Pull解析XML格式數(shù)據(jù)的使用示例,Pull是Android中自帶的XML解析器,Java里也是一樣用:D需要的朋友可以參考下2016-04-04
android效果TapBarMenu繪制底部導(dǎo)航欄的使用方式示例
本篇文章主要介紹了android效果TapBarMenu繪制底部導(dǎo)航欄的使用方式,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-01-01
Android開(kāi)發(fā)之Location用法實(shí)例分析
這篇文章主要介紹了Android開(kāi)發(fā)中Location用法,結(jié)合實(shí)例形式分析了Android使用location控件獲取經(jīng)緯度信息的相關(guān)操作技巧,需要的朋友可以參考下2016-10-10
Android自定義View實(shí)現(xiàn)仿GitHub的提交活躍表格
這篇文章主要介紹了Android自定義View實(shí)現(xiàn)仿GitHub的提交活躍表格,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下吧2017-01-01

