Picasso入门教程(七) 根据图片的优先级按顺序请求

优先级:高优先级、中优先级、低优先级

你可能正在想一个符合这个的情景,但是如果你想需要按照优先级来加载图片,你可以使用priority() 这个方法。这需要使用三个常量:HIGH ,MEDIUMLOW .默认的,所有的请求都使用MEDIUM 。赋予图片不同的加载优先级将会影响到Picasso的加载行为。

例子

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/activity_request_priority_hero"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_margin="5dp"/>

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:text="Sweets"
            android:textAppearance="?android:attr/textAppearanceLarge"/>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:text="Lorem Ipsum is simply dummy text"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_gravity="center_horizontal"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/activity_request_priority_low_left"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/activity_request_priority_low_right"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"/>
        </LinearLayout>

    </LinearLayout>
</ScrollView>

这个xml的代码并不是很重要。你只需要知道他是下面的布局即可。这里写图片描述

例子:activity的代码

在我们的activity中,我们只需要加载需要展示在三个ImageView上面的图片。你应该知道如何使用Picasso发出正确的请求。下面这张图片将得到HIGH 的优先级。

Picasso
    .with(context)
    .load(UsageExampleListViewAdapter.eatFoodyImages[0])
    .fit()
    .priority(Picasso.Priority.HIGH)
    .into(imageViewHero);

下面的两张小图片将是LOW 的优先级。

Picasso
    .with(context)
    .load(UsageExampleListViewAdapter.eatFoodyImages[1])
    .fit()
    .priority(Picasso.Priority.LOW)
    .into(imageViewLowPrioLeft);

Picasso
    .with(context)
    .load(UsageExampleListViewAdapter.eatFoodyImages[2])
    .fit()
    .priority(Picasso.Priority.LOW)
    .into(imageViewLowPrioRight);

很重要的一点是,你自己指定的Picasso的请求并不是有效的。你应该使用Picasso Priorities 来改变Picasso的请求而不是改变自己请求的顺序。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值