ScrollView可实现控件在超出屏幕范围的情况下滚动显示。

用法:在XML文件中将需滚动的控件包含在ScrollView中,当控件超出屏幕范围时可通过滚动查看;ScrollView也提供了一些方法来控制自身的显示情况。

1.ScrollView中包含其他控件

android:id="@+id/scrollView_showMessages"

android:layout_width="fill_parent"

android:layout_height="310dp"

>

android:id="@+id/textView_showMessages"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:textSize="25dp"

/>

2.onCreate()中findView:

mScrollView_showMessages=(ScrollView) findViewById(R.id.scrollView_showMessages);

3.在需要的地方,让ScrollView滚动至指定位置

mScrollView_showMessages.scrollTo(0, mTextView_showMessages.getBottom());

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐