一個強大的Android view looper 庫:FlycoBanner-Matser

jopen 9年前發布 | 33K 次閱讀 Android開發 移動開發 FlycoBanner-Matser

一個強大的android view looper 庫,以簡化日常開發這種高頻率的功能。支持安卓2.2及更高版本。

Background

Image loop banner is high frequency used in most apps. So is the app of the company I work for. At first, this is only used in home page. Later with the app update, there are some simliar functions needed in other pages both image and text. I copy the same code here and there, finally I can not standing copying anymore. I explore on the github to find libs that meet my needs. Though I find some poewful libs, but the lib what I want should support view looping not only ImageView. And I do not want a lib having a ImageLoad Framework inside. So I decide to code a libray with features below:

  • Use Executors instead of Task
  • Supports both normal banner and endless auto loop banner
  • Supports inflate item view and logic operation such as loading image outside.
  • Supports set source using data list with different entity
  • Supports smartly pause scroll and continue scroll.
    • Touch down pause. Touch up continue.
    • Window of activty off pause.Window of activty on continue.
  • Supports inner indictaors
  • Supports page transformer (not often used in my daily work, just support this feature for others if needed)

Demo

Here is a DemoApk download

Gradle

dependencies{
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.flyco.banner:FlycoBanner_Lib:1.0.1@aar'
}

Usage

Extends BaseIndicaorBanner and Set Data Type

public class SimpleImageBanner extends BaseIndicaorBanner<BannerItem, SimpleImageBanner> {
    private ColorDrawable colorDrawable;

    public SimpleImageBanner(Context context) {
        this(context, null, 0);
    }

    public SimpleImageBanner(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SimpleImageBanner(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        colorDrawable = new ColorDrawable(Color.parseColor("#555555"));
    }

    @Override
    public void onTitleSlect(TextView tv, int position) {
        final BannerItem item = list.get(position);
        tv.setText(item.title);
    }

    @Override
    public View onCreateItemView(int position) {
        View inflate = View.inflate(context, R.layout.adapter_simple_image, null);
        ImageView iv = ViewFindUtils.find(inflate, R.id.iv);

        final BannerItem item = list.get(position);
        int itemWidth = dm.widthPixels;
        int itemHeight = (int) (itemWidth * 360 * 1.0f / 640);
        iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
        iv.setLayoutParams(new LinearLayout.LayoutParams(itemWidth, itemHeight));

        String imgUrl = item.imgUrl;

        if (!TextUtils.isEmpty(imgUrl)) {
            Glide.with(context)
                    .load(imgUrl)
                    .override(itemWidth, itemHeight)
                    .centerCrop()
                    .placeholder(colorDrawable)
                    .into(iv);
        } else {
            iv.setImageDrawable(colorDrawable);
        }

        return inflate;
    }
}

項目主頁:http://www.baiduhome.net/lib/view/home/1442666871993

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!