首页 > 软件开发 > ANDROID >

Android如何使用scroll view组件

来源:互联网 2023-03-17 00:09:35 89

Android如何使用scroll view组件KP0办公区 - 实用经验教程分享!

Android如何使用scroll view组件KP0办公区 - 实用经验教程分享!

工具/原料

  • android studio

方法/步骤

  • 1

    首先打开android main xml布局文件KP0办公区 - 实用经验教程分享!

    Android如何使用scroll view组件KP0办公区 - 实用经验教程分享!

  • 2

    找到scroll view 并且添加到视图KP0办公区 - 实用经验教程分享!

    Android如何使用scroll view组件KP0办公区 - 实用经验教程分享!

  • 3

    main的布局文件代码关键部分:KP0办公区 - 实用经验教程分享!

    KP0办公区 - 实用经验教程分享!

    ScrollView android:id="@ id/scrollView" android:layout_width="match_parent" android:layout_height="wrap_content" android:fadeScrollbars="false">TextView android:id="@ id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" />/ScrollView>KP0办公区 - 实用经验教程分享!

  • 4

    然后在strings.xml设置文本内容KP0办公区 - 实用经验教程分享!

    Android如何使用scroll view组件KP0办公区 - 实用经验教程分享!

  • 4该信息非法爬取自百度经验
  • 5

    回到main activity中,在其Java代码中加入如图的代码:KP0办公区 - 实用经验教程分享!

    主要是先findviewbyid,然后直接对textview操作即可。KP0办公区 - 实用经验教程分享!

    oncreate部分KP0办公区 - 实用经验教程分享!

    KP0办公区 - 实用经验教程分享!

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView=findViewById(R.id.textView1); contents=new StringBuilder(); for(int i=0;i=1000;i ) contents.append(R.string.content); textView.setText(contents);}KP0办公区 - 实用经验教程分享!

    Android如何使用scroll view组件KP0办公区 - 实用经验教程分享!

  • 6

    当然我们也是可以通过Android如何使用scroll view组件来设置侧边的滚动条的状态。KP0办公区 - 实用经验教程分享!

    Android如何使用scroll view组件KP0办公区 - 实用经验教程分享!

  • 7

    最后的实现效果KP0办公区 - 实用经验教程分享!

    Android如何使用scroll view组件KP0办公区 - 实用经验教程分享!

  • 以上方法由办公区教程网编辑摘抄自百度经验可供大家参考!KP0办公区 - 实用经验教程分享!


    标签: Android

    办公区 Copyright © 2016-2023 www.bgqu.net. Some Rights Reserved. 备案号:湘ICP备2020019561号统计代码