1. 程式人生 > >萬能的公告欄輪播 View,也可用於商品個性垂直輪播展示

萬能的公告欄輪播 View,也可用於商品個性垂直輪播展示

BulletinView

專案地址:Bakumon/BulletinView 

簡介::camel: 萬能的公告欄輪播 View,也可用於商品個性垂直輪播展示

更多:作者   提 Bug   

標籤:

 

Download

:camel: 萬能的公告欄輪播 View,也可用於商品個性垂直輪播展示

預覽圖

BulletinView.gif

Demo 下載體驗

去蒲公英下載

使用

下載

compile 'me.bakumon:bulletinview:1.0.0'

自定義屬性

屬性 描述 型別
bulletinInterval 輪播間隔時間 毫秒,預設 3000
bulletinEnterAnim 公告進入動畫 動畫資源 ID,預設漸入平移
bulletinLeaveAnim 公告離開動畫 動畫資源 ID,預設漸出平移

XML

<me.bakumon.library.view.BulletinView
    android:id="@+id/bulletin_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:bulletinEnterAnim="@anim/bulletin_item_enter"
    app:bulletinLeaveAnim="@anim/bulletin_item_leave"
    app:bulletinInterval="3000" />

普通公告

效果圖的第一種樣式

預設提供了 SimpleBulletinAdapter 介面卡。

mBulletinView = (BulletinView) findViewById(R.id.bulletin_view);
List<String> list = new ArrayList<>();
list.add("智慧數碼手錶 12 期免息!");
list.add("領券家電立減 800");
mBulletinView.setAdapter(new SimpleBulletinAdapter(this, list));

複雜公告

效果圖的第二種樣式

需要建立介面卡繼承自 BulletinAdapter<T>

public class SaleAdapter extends BulletinAdapter<SaleEntity> {

    public SaleAdapter(Context context, List<SaleEntity> data) {
        super(context, data);
    }

    @Override
    public View getView(int position) {
        // 獲取 item 根 view
        View view = getRootView(R.layout.item_sale);
        // 例項化子 View
        TextView tVSaleTitle = (TextView) view.findViewById(R.id.tv_sale_title);
        // 獲取當前 bean
        SaleEntity saleEntity = mData.get(position);
        // 設定 view 顯示的值
        tVSaleTitle.setText(saleEntity.saleTitle);

        return view;
    }
}

給 BulletinView 設定自定義的 Adapter 即可。

mBulletinViewSale = (BulletinView) findViewById(R.id.bulletin_view_sale)
List<SaleEntity> saleEntities = new ArrayList<>();

// ...
// 省略 new 物件操作

saleEntities.add(saleEntity);
saleEntities.add(saleEntity1);
mBulletinViewSale.setAdapter(new SaleAdapter(this, saleEntities));

設定點選事件監聽

mBulletinView.setOnBulletinItemClickListener(new BulletinView.OnBulletinItemClickListener() {
    @Override
    public void onBulletinItemClick(int position) {
        Toast.makeText(MainActivity.this, "click:" + position, Toast.LENGTH_SHORT).show();
    }
});
`

關於我

E-mail:[email protected]

個人部落格: https://www.bakumon.me/

Github: https://github.com/Bakumon

License

Copyright 2017 [email protected]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.