效果
字体长度过大滚动字体,结束后上下滚动公告控件
Gradle
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation 'com.github.cyh120190774:ScrollNoticeView:1.00'
}
使用
xml
<com.cyh.scrollnoticeview.ScrollNoticeView
android:id="@+id/tv_notice1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="10dp"
app:nsvInterval="3000"
app:nsvTextColor="#4071FF"
app:nsvTextSize="12sp" />
Java
binding.tvNotice1.start(Arrays.asList(notices));
binding.tvNotice1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, notices[binding.tvNotice1.getIndex()], Toast.LENGTH_SHORT).show();
}
});
属性
<declare-styleable name="ScrollNoticeView">
<!-- 图标 -->
<attr name="nsvIcon" format="reference" />
<!-- 图标与内容的间隙 -->
<attr name="nsvIconPadding" format="dimension" />
<!-- 图标颜色 -->
<attr name="nsvIconTint" format="color" />
<!-- 文本尺寸 -->
<attr name="nsvTextSize" format="dimension" />
<!-- 文本颜色 -->
<attr name="nsvTextColor" format="color" />
<!-- 文本最大行数 -->
<attr name="nsvTextMaxLines" format="integer" />
<!-- 切换动画间隔时间,毫秒 -->
<attr name="nsvInterval" format="integer" />
<!-- 切换动画持续时间,毫秒 -->
<attr name="nsvDuration" format="integer" />
<!-- 文字滚动速度 负数为向右-->
<attr name="nsvSpeed" format="integer" />
<!-- 文字开始滚动的延时-->
<attr name="nsvDelay" format="integer" />
</declare-styleable>