{"id":13643401,"url":"https://github.com/guojunustb/VerticalBannerView","last_synced_at":"2025-04-21T01:32:28.744Z","repository":{"id":217102466,"uuid":"50168206","full_name":"guojunustb/VerticalBannerView","owner":"guojunustb","description":"a vertical banner view in android.you can find it in 淘宝app、京东app...","archived":false,"fork":false,"pushed_at":"2016-10-20T02:59:23.000Z","size":445,"stargazers_count":435,"open_issues_count":0,"forks_count":119,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-09T15:42:31.809Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guojunustb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-22T08:27:55.000Z","updated_at":"2024-10-20T07:51:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"37b1ae5e-5e24-4f28-a768-b4d6bafc299e","html_url":"https://github.com/guojunustb/VerticalBannerView","commit_stats":null,"previous_names":["guojunustb/verticalbannerview"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guojunustb%2FVerticalBannerView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guojunustb%2FVerticalBannerView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guojunustb%2FVerticalBannerView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guojunustb%2FVerticalBannerView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guojunustb","download_url":"https://codeload.github.com/guojunustb/VerticalBannerView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249982623,"owners_count":21355735,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:01:46.932Z","updated_at":"2025-04-21T01:32:28.012Z","avatar_url":"https://github.com/guojunustb.png","language":"Java","funding_links":[],"categories":["跑马灯"],"sub_categories":[],"readme":"### VerticalBannerView\n\n`VerticalBannerView`是一个android平台下的自定义控件,通常用来展示广告,类似`淘宝头条`,它的样式如下:\n\n![](art.gif)\n\n### Feature\n\n1. 可自由定义展示的内容\n2. 使用方式类似ListView/RecyclerView\n3. 可为当前的内容添加各种事件,比如点击打开某个页面等\n\n### Attention\n\nAPI \u003e= 11\n\n### Usage\n\n可以类比`ListView`\n\n0. 添加依赖\n\n    - Add it in your root build.gradle at the end of repositories:\n\n        ```\n        \n            allprojects {\n                repositories {\n                    ...\n                    maven { url \"https://jitpack.io\" }\n                }\n            }\n        ```\n    - Add the dependency\n        \n        ```\n        dependencies {\n        \t        compile 'com.github.Rowandjj:VerticalBannerView:1.0'\n        \t}\n        ```\n\n\n1. 定义item的布局\n    \n    ```\n    \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n    \u003cRelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n                  android:orientation=\"vertical\"\n                  android:layout_width=\"match_parent\"\n                  android:background=\"#000\"\n                    android:gravity=\"center_vertical\"\n                  android:layout_height=\"60dp\"\u003e\n    \n        \u003cImageView\n            android:layout_marginLeft=\"10dp\"\n            android:id=\"@+id/iv\"\n            android:src=\"@android:drawable/ic_dialog_email\"\n            android:layout_width=\"30dp\"\n            android:layout_height=\"30dp\"\n            /\u003e\n    \n        \u003cTextView\n            android:id=\"@+id/tv_02\"\n            android:text=\"hello world\"\n            android:layout_marginLeft=\"10dp\"\n            android:textSize=\"16sp\"\n            android:layout_toRightOf=\"@id/iv\"\n            android:paddingLeft=\"5dp\"\n            android:textColor=\"#fff\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"/\u003e\n    \n        \u003cTextView\n            android:layout_below=\"@id/tv_02\"\n            android:text=\"I am detail message......\"\n            android:layout_marginLeft=\"10dp\"\n            android:textSize=\"14sp\"\n            android:layout_centerVertical=\"true\"\n            android:layout_toRightOf=\"@id/iv\"\n            android:paddingLeft=\"5dp\"\n            android:textColor=\"#fff\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"/\u003e\n    \u003c/RelativeLayout\u003e\n    ```\n\n2. 实现adapter\n\n    ```\n    public class SampleAdapter01 extends BaseBannerAdapter\u003cModel01\u003e {\n    \n        private List\u003cModel01\u003e mDatas;\n    \n        public SampleAdapter01(List\u003cModel01\u003e datas) {\n            super(datas);\n        }\n    \n        @Override\n        public View getView(VerticalBannerView parent) {\n            return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_01,null);\n        }\n    \n        @Override\n        public void setItem(final View view, final Model01 data) {\n            TextView tv = (TextView) view.findViewById(R.id.tv_01);\n            tv.setText(data.title);\n            //你可以增加点击事件\n            view.setOnClickListener(new View.OnClickListener() {\n                @Override\n                public void onClick(View v) {\n                    //比如打开url\n                    Toast.makeText(view.getContext(),data.url,Toast.LENGTH_SHORT).show();\n                }\n            });\n        }\n    }\n    ```\n\n3. 在布局中增加view的声明\n\n    ```\n       \u003ccom.taobao.library.VerticalBannerView\n                android:id=\"@+id/banner_01\"\n                android:layout_width=\"match_parent\"\n                android:layout_height=\"40dp\"\n                app:animDuration=\"900\" ----\u003e动画间隔900ms\n                app:gap=\"2000\"/\u003e -----\u003e切换时长2000ms\n    ```\n\n4. 设置Adapter并启动\n\n    ```\n    List\u003cModel01\u003e datas02 = new ArrayList\u003c\u003e();\n    datas02.add(new Model01(\"Life was so beautiful\",\"---\u003eLife was so beautiful,\"));\n    datas02.add(new Model01(\"From morning to evening\",\"---\u003eFrom morning to evening\"));\n    datas02.add(new Model01(\"We enjoyed the road to school\",\"---\u003eWe enjoyed the road to school,\"));\n    datas02.add(new Model01(\"Birds chirped and Peace lingered\",\"---\u003eBirds chirped and Peace lingered\"));\n    final SampleAdapter02 adapter02 = new SampleAdapter02(datas02);\n    final VerticalBannerView banner02 = (VerticalBannerView) findViewById(R.id.banner_02);\n    banner02.setAdapter(adapter02);\n    banner02.start();\n    ```\n\n5. 更新数据\n\n    ```\n    List\u003cModel01\u003e newData = new ArrayList\u003c\u003e();\n    newData.add(new Model01(\"锄禾日当午\",\"---\u003e锄禾日当午\"));\n    newData.add(new Model01(\"汗滴禾下土\",\"---\u003e汗滴禾下土\"));\n    newData.add(new Model01(\"谁知盘中餐\",\"---\u003e谁知盘中餐\"));\n    newData.add(new Model01(\"粒粒皆辛苦\",\"---\u003e粒粒皆辛苦\"));\n    adapter02.setData(newData);\n    \n    ```\n    \n6. 停止\n\n    ```\n    banner02.stop();\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguojunustb%2FVerticalBannerView","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguojunustb%2FVerticalBannerView","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguojunustb%2FVerticalBannerView/lists"}