100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > android TextView 带滚动条 和ScrollView 用法(暂时觉得ScrollView滑动速度比较快)

android TextView 带滚动条 和ScrollView 用法(暂时觉得ScrollView滑动速度比较快)

时间:2019-03-31 09:41:02

相关推荐

android TextView 带滚动条 和ScrollView 用法(暂时觉得ScrollView滑动速度比较快)

本来是想做一个显示文字信息的,当文字很多时View的高度不能超过一个固定的值,当文字很少时View的高度小于那个固定值时,按View的高度显示。因为ScrollView没有maxHeight,无法满足需求,只好另找方法了。

View本身是可以设置ScrollBar,这样就不一定需要依赖ScrollView了。TextView有个属性maxLine,这样也就满足了需求了,只要设置一个TextView带ScrollBar的,然后设置maxLine就可以了。

<TextViewandroid:id="@+id/text_view"android:layout_width="fill_parent"android:layout_height="wrap_content"android:singleLine="false"android:maxLines="10"android:scrollbars="vertical"/>

<TextViewandroid:id="@+id/text_view"android:layout_width="fill_parent"android:layout_height="wrap_content"android:singleLine="false"android:maxLines="10"android:scrollbars="vertical"/>

还需要在代码了设置TextView可以滚动。

TextViewtextView=(TextView)findViewById(R.id.text_view); textView.setMovementMethod(ScrollingMovementMethod.getInstance());

------------------------------------------------------------------------------------------------------------------------------------------

如果用ScrollView ,代码如下,<ScrollView

android:layout_width="745dip"

android:layout_height="520dip"

android:id="@+id/mBtnRe2"

android:layout_marginTop="30dip"

android:layout_marginLeft="30dip"

android:fadingEdge="none"

>

<TextView

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:id="@+id/mTxtContent"

android:textSize="25sp"

android:textColor="#000000"

android:fadingEdge="none"

/>

</ScrollView>

--------------------------------------------------------------------------------------------------------------------------------------------

ScrollView可以调整滑动速度,自己实现ScrollView

**

* 快/慢滑动ScrollView * @author 农民伯伯 * */ public class SlowScrollView extends ScrollView {public SlowScrollView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle); } public SlowScrollView(Context context, AttributeSet attrs) {super(context, attrs); } public SlowScrollView(Context context) {super(context); } /** * 滑动事件 */ @Override public void fling(int velocityY) {super.fling(velocityY / 4); } }复制代码代码说明:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。