在app下面的build.gradle文件中引用第三方的类库:

  buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }    sourceSets {        main {            jniLibs.srcDirs = ['libs']        }    }}dependencies {    implementation fileTree(include: ['*.jar'], dir: 'libs')    implementation 'com.android.support:appcompat-v7:26.1.0'    implementation 'com.android.support.constraint:constraint-layout:1.0.2'    testImplementation 'junit:junit:4.12'    androidTestImplementation 'com.android.support.test:runner:1.0.1'    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'    compile 'com.veinhorn.scrollgalleryview:library:1.0.2'}
   
在xml里面添加控件
<com.veinhorn.scrollgalleryview.ScrollGalleryView    android:id="@+id/scrollView"    android:layout_width="wrap_content"    android:layout_height="match_parent"    android:background="@color/colorAccent" />
在java代码里面添加:
public class PhotoActivity extends FragmentActivity {    private ScrollGalleryView scrollGalleryView;    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_photo);        scrollGalleryView = (ScrollGalleryView)findViewById(R.id.scrollView);        scrollGalleryView                .setThumbnailSize(100)                .setZoom(true)                .setFragmentManager(getSupportFragmentManager())                .addImage(R.mipmap.a1)                .addImage(R.mipmap.a2)                .addImage(R.mipmap.a3)                .addImage(R.mipmap.a4)                .addImage(R.mipmap.a2)                .addImage(R.mipmap.a3)                .addImage(convertDrawableToBitmap(R.mipmap.a4));    }    private Bitmap convertDrawableToBitmap(int image) {        return ((BitmapDrawable)getResources().getDrawable(image)).getBitmap();    }}
总结:

这是android studio的一个第三方的控件,需要导入库文件,本例子只是展示资源文件夹的图片,如果需要实现手机效果,需要获取手机相册的路径,然后使用addImage方法添加图片资源即可

运行效果截图:
实现Android的图片画廊控件ScrollGalleryView_第1张图片



更多相关文章

  1. android代码编写布局和控件
  2. Android Widget添加自定义控件
  3. widget 常用UI控件介绍
  4. Android 代码当中动态改变某个控件的位置
  5. Android相机相册的调用,图片的存储删除
  6. Android 手势滑动动画效果收集整理
  7. Android实用图片显示控件photoview
  8. Android Studio学习:简单控件:Button控件的点击、长按函数重写

随机推荐

  1. 中国的 Android:尚未发掘的应用市场?
  2. 做好准备,让你的短信应用迎接Android(安卓
  3. android开发——通过子线程更新界面UI
  4. Android 内功心法(1.2)——android常用设
  5. Android系统信息获取 之十二:获取屏幕分辨
  6. Android 自定义组件
  7. android 模拟器的使用(Android模拟器介绍
  8. Android加载Gif图片的一般方法:Movie实现
  9. Android初学的学习笔记
  10. 2019AndroidBAT.字节跳动74道高级面试第