最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實現(xiàn)漂亮的Gallery畫廊

 更新時間:2020年08月26日 15:09:12   作者:Vivinia_Vivinia  
這篇文章主要為大家詳細介紹了Android實現(xiàn)漂亮的Gallery畫廊,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android實現(xiàn)Gallery畫廊的具體代碼,供大家參考,具體內(nèi)容如下

僅是實現(xiàn)基本功能,頁面粗糙請見諒

圖片下標0開始

activity_main.xml頁面:

<?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頁面:

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頁面:

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)的點擊事件
  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();
   }
  });
 }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

镇江市| 镇宁| 梓潼县| 绥宁县| 湘潭县| 永济市| 武定县| 建平县| 观塘区| 乌海市| 日照市| 灵寿县| 区。| 高淳县| 蓬莱市| 开原市| 贺州市| 托克托县| 乌海市| 淮滨县| 安阳市| 蓝山县| 九龙县| 遂溪县| 桐乡市| 平凉市| 项城市| 新乡市| 阿鲁科尔沁旗| 霸州市| 肇东市| 和政县| 张掖市| 元江| 浦北县| 肇东市| 卫辉市| 刚察县| 元江| 九江市| 永定县|