fresco加载图片 动图 左右滑动图片

  加依赖 

   compile 'com.facebook.fresco:fresco:1.5.0'
    // For animated GIF support
    compile 'com.facebook.fresco:animated-gif:1.5.0'
    // For WebP support, including animated WebP
    compile 'com.facebook.fresco:animated-webp:1.5.0'
    compile 'com.facebook.fresco:webpsupport:1.5.0'
    // For WebP support, without animations
    compile 'com.facebook.fresco:webpsupport:1.5.0'


 

在加载图片之前,你必须初始化Fresco类。你只需要调用Fresco.initialize一次即可完成初始化,在Application 里面做这件事再适合不过了(如下面的代码),注意多次的调用初始化是无意义的。

1
2
3
4
5
6
7
8
[MyApplication.java]
public class MyApplication extends Application {
	@Override
	public void onCreate() {
		super.onCreate();
		Fresco.initialize(this);
	}
}

做完上面的工作后,你需要在 AndroidManifest.xml 中指定你的 Application 类。为了下载网络图片,请确认你声明了网络请求的权限。

1
2
3
4
5
6
7
8
9
10
11
12
13
  <manifest
    ...
    >
    <uses-permission android:name="android.permission.INTERNET" />
    <application
      ...
      android:label="@string/app_name"
      android:name=".MyApplication"
      >
      ...
    </application>
    ...
  </manifest>

在xml布局文件中, 加入命名空间:

1
2
3
4
5
6
<!-- 其他元素-->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

加入SimpleDraweeView:  圆图片属性:

 fresco:roundAsCircle="true"

1
2
3
4
5
6
<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/my_image_view"
    android:layout_width="130dp"
    android:layout_height="130dp"
    fresco:placeholderImage="@drawable/my_drawable"
  />

开始加载图片:

1
2
3
Uri uri = Uri.parse("https://raw.githubusercontent.com/facebook/fresco/gh-pages/static/logo.png");
SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);
draweeView.setImageURI(uri);
1、HorizontalScrollView的简单用法

HorizontalScrollView其实是FrameLayout的子类,所以内部只能有一个直接的子View。我们用来做Gallery效果,首选当然是LinearLayout,然后方向设置为水平。

1、布局文件:

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.      >  
  6.     <HorizontalScrollView  
  7.         android:layout_width="wrap_content"  
  8.         android:layout_height="150dp"  
  9.         android:layout_gravity="center_vertical"  
  10.         android:background="#AA444444"  
  11.         android:scrollbars="none" >  
  12.   
  13.         <LinearLayout  
  14.             android:id="@+id/id_gallery"  
  15.             android:layout_width="wrap_content"  
  16.             android:layout_height="wrap_content"  
  17.             android:layout_gravity="center_vertical"  
  18.             android:orientation="horizontal" >  
  19.         </LinearLayout>  
  20.     </HorizontalScrollView>  
  21.   
  22. </LinearLayout>  
<LinearLayout 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"
     >
    <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="150dp"
        android:layout_gravity="center_vertical"
        android:background="#AA444444"
        android:scrollbars="none" >

        <LinearLayout
            android:id="@+id/id_gallery"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:orientation="horizontal" >
        </LinearLayout>
    </HorizontalScrollView>

</LinearLayout>

很简单,就一个HorizontalScrollView内部有个水平方向的LinearLayout
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值