##??????????????????
???
??
compile 'com.oushangfeng:MarqueeLayout:1.0.4'
??
Attribute ?? | Description ?? |
---|---|
switchTime | ??????????? |
scrollTime | ??????? |
orientation | ???????up?down?left?right???? |
enableAlphaAnim | ????????View?????? |
enableScaleAnim | ????????View????? |
XML
<com.oushangfeng.marqueelayout.MarqueeLayout
android:id="@+id/marquee_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#118866"
app:enableAlphaAnim="true"
app:enableScaleAnim="false"
app:orientation="up">
</com.oushangfeng.marqueelayout.MarqueeLayout>
<com.oushangfeng.marqueelayout.MarqueeLayout
android:id="@+id/marquee_layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/marquee_layout"
android:background="#dcdcdc"
app:enableAlphaAnim="true"
app:enableScaleAnim="true"
app:orientation="left">
</com.oushangfeng.marqueelayout.MarqueeLayout>
<Button
android:id="@+id/bt_delete"
android:onClick="deleteSrc"
android:text="????"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:onClick="addSrc"
android:text="????"
android:layout_above="@+id/bt_delete"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
??????????????InitViewCallBack?????
mMarqueeLayout = (MarqueeLayout) findViewById(R.id.marquee_layout);
mSrcList = new ArrayList<>();
mSrcList.add("???????? ?????????");
mSrcList.add("?????????? ?????? ????");
mSrcList.add("??????????????? ??????????????");
mSrcList.add("?????? ?????");
mSrcAdapter = new MarqueeLayoutAdapter<String>(mSrcList) {
@Override
public int getItemLayoutId() {
return R.layout.item_simple_text;
}
@Override
public void initView(View view, int position, String item) {
((TextView) view).setText(item);
}
}
;
mMarqueeLayout.setAdapter(mSrcAdapter);
mMarqueeLayout.start();
mMarqueeLayout1 = (MarqueeLayout) findViewById(R.id.marquee_layout1);
final List<String> imgs = new ArrayList<>();
imgs.add("http://img3.imgtn.bdimg.com/it/u=936722914,2010466745&fm=11&gp=0.jpg");
imgs.add("http://img5.imgtn.bdimg.com/it/u=793061750,504065085&fm=11&gp=0.jpg");
imgs.add("http://img5.imgtn.bdimg.com/it/u=506823331,38014690&fm=11&gp=0.jpg");
imgs.add("http://h.hiphotos.baidu.com/baike/pic/item/2fdda3cc7cd98d10e6a5b4aa273fb80e7bec903c.jpg");
MarqueeLayoutAdapter<String> adapter1 = new MarqueeLayoutAdapter<String>(imgs) {
@Override
public int getItemLayoutId() {
return R.layout.item_simple_image;
}
@Override
public void initView(View view, int position, String item) {
Glide.with(view.getContext()).load(item).into((ImageView) view);
}
}
;
// ????????????????id???????view?id???????????????????view
adapter1.setItemClickListener(new OnItemClickListener() {
@Override
public void onClick(View view, int position) {
Log.e("TAG", "MainActivity-74?-onClick(): " + position);
}
}
, R.id.iv);
mMarqueeLayout1.setAdapter(adapter1);
mMarqueeLayout1.start();
// ???
public void deleteSrc(View view) {
if (mSrcList.size() != 0) {
mSrcList.remove(mSrcList.size() - 1);
mSrcAdapter.notifyDataSetChanged();
}
}
// ????
public void addSrc(View view) {
if (mSrcList != null) {
Random random = new Random();
mSrcList.add("????: " + random.nextInt(12345));
mSrcAdapter.notifyDataSetChanged();
}
}
??
???????support?
License
Copyright 2016 oubowu 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.