• Android学习笔记 69. 文本和滚动视图


    Android学习笔记

    Android 开发者基础知识 (Java) —— Google Developers 培训团队

    第1单元 入门

    第1课 构建首个应用

    69. 文本和滚动视图

    你会做什么
    • 创建 ScrollingText 应用程序。
    • 将 更改ConstraintLayout ViewGroupRelativeLayout
    • TextView为文章标题和副标题添加两个元素。
    • TextAppearance为文章标题和副标题使用样式和颜色。
    • 在文本字符串中使用 HTML 标记来控制格式。
    • 使用该lineSpacingExtra属性添加行距以提高可读性。
    • 将 a 添加ScrollView到布局以启用滚动TextView元素。
    • 添加autoLink属性以使文本中的 URL 处于活动状态且可单击。
    69.1 添加和编辑TextView元素
    1. 创建项目和TextView元素

      在这里插入图片描述

      修改默认布局为【相对布局】

      在这里插入图片描述

      添加控件

      在这里插入图片描述

      
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context=".MainActivity">
      
          <TextView
              android:id="@+id/article_heading"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="@color/design_default_color_primary"
              android:padding="@dimen/padding_regular"
              android:text="@string/article_title"
              android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
              android:textColor="@color/white"
              android:textStyle="bold" />
      
          <TextView
              android:id="@+id/article_subheading"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_below="@id/article_heading"
              android:padding="@dimen/padding_regular"
              android:text="@string/article_subtitle"
              android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large" />
      
      
          <TextView
              android:id="@+id/article"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_below="@id/article_subheading"
              android:lineSpacingExtra="@dimen/line_spacing"
              android:padding="@dimen/padding_regular"
              android:text="@string/article_text"
      
              />
      
      RelativeLayout>
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      • 23
      • 24
      • 25
      • 26
      • 27
      • 28
      • 29
      • 30
      • 31
      • 32
      • 33
      • 34
      • 35
      • 36
      • 37
      • 38
      • 39
      • 40
    2. 添加文章正文

      <resources>
          <string name="app_name">ScrollingTextstring>
      
      
      
      
          <string name="article_title">Beatles Anthology Vol. 1string>
          <string name="article_subtitle">Behind That Locked Door: Beatles Rarities!string>
          <string name="article_text">In a vault deep inside Abbey Road Studios in London — protected by an unmarked, triple-locked, police-alarmed door — are something like 400 hours of unreleased Beatles recordings, starting from June 2, 1962 and ending with the very last tracks recorded for the <i>Let It Bei> album. The best of the best were released by Apple Records in the form of the 3-volume Anthology series.
              For more information, see the Beatles Time Capsule at www.rockument.com.
      \n\n
      This volume starts with the first new Beatle song, “Free as a Bird” (based on a John Lennon demo, found only on <i>The Lost Lennon Tapes Vol. 28i>, and covers the very earliest historical recordings, outtakes from the first albums, and live recordings from early concerts and BBC Radio sessions.
      \n\n
      <b>Highlights include:b>
      \n\n
      <b><i>Cry for a Shadowi>b> - Many a Beatle fanatic started down the outtake road, like I did, with a first listen to this song. Originally titled “Beatle Bop” and recorded in a single session that yielded four songs (the other three featured Tony Sheridan with the Beatles as a backing band), “Cry for a Shadow” is an instrumental written by Lennon and Harrison, which makes it unique to this day. John Lennon plays rhythm guitar, George Harrison plays lead guitar, Paul McCartney plays bass, and Pete Best plays drums. The sessions were produced by Bert Kaempfert in Hamburg, Germany, during the Beatles’ second visit from April through July of 1961 to play in the Reeperbahn-section clubs.
      \n\n
      <b><i>My Bonniei>b> and <b><i>Ain’t She Sweeti>b> — At the same session, the Beatles played on “My Bonnie” (the first-ever single with Beatles playing), as the backing band for English singer Tony Sheridan, originally a member of the Jets. The popularity of this single in Liverpool brought the Beatles to the attention of Brian Epstein, who worked in the NEMS record store and tried to meet demand for the disc. John Lennon then sings a fine “Ain’t She Sweet” (his first-ever released vocal).
      \n\n
      <b><i>Searchini>b> — A Jerry Leiber - Mike Stoller comedy song that was a hit for the Coasters in 1957, and a popular live favorite of the Beatles. The Coasters also had a hit with “Besame Mucho” and the Beatles covered that song as well. Ringo Starr had by now replaced Pete Best on drums. The high falsetto is George, who also plays a hesitant lead guitar. This is from their first audition for Decca Records in London on Jan 1., 1962, live in the studio. The Grateful Dead would later cover “Searchin” with a similar arrangement, Pigpen doing the Paul vocals. A live version is available on outtake records featuring the Dead joined by the Beach Boys!
      \n\n
      <b><i>Love Me Doi>b> — An early version of the song, played a bit slower and with more of a blues feeling, and a cool bossa-nova beat in middle. Paul had to sing while John played harmonica — a first for the group. Pete Best played drums on this version.
      \n\n
      <b><i>She Loves You – Till There Was You – Twist and Shouti>b> — Live at the Princess Wales Theatre by Leicester Square in London, attended by the Queen. “Till There Was You” (by Meredith Wilson) is from the musical The Music Man and a hit for Peggy Lee in 1961. Before playing it, Paul said it was recorded by his favorite American group, “Sophie Tucker” (which got some laughs). At the end, John tells the people in the cheaper seats to clap their hands, and the rest to “rattle your jewelry” and then announces “Twist and Shout” (a song by Bert Russell and Phil Medley that was first recorded in 1962 by the Isley Brothers). A film of the performance shows the Queen smiling at John’s remark.
      \n\n
      <b><i>Leave My Kitten Alonei>b> — One of the lost Beatle songs recorded during the “Beatles For Sale” sessions but never released. This song, written by Little Willie John, Titus Turner, and James McDougal, was a 1959 R&B hit for Little Willie John and covered by Johnny Preston before the Beatles tried it and shelved it. A reference to a “big fat bulldog” may have influenced John’s “Hey Bulldog” (Yellow Submarine album), which is a similar rocker.
      \n\n
      <b><i>One After 909i>b> — A song recorded for the <i>Let It Bei> album was actually worked on way back in the beginning, six years earlier. This take shows how they did it much more slowly, with an R&B feel to it.
      string>
      
      resources>
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      • 23
      • 24
      • 25
      • 26
      • 27
      • 28
      • 29
      • 30
      • 31
    3. 运行

      在这里插入图片描述

    69.2 添加一个ScrollView和一个Activity链接
    1. 为Activity的网络链接添加autoLink属性

      在这里插入图片描述

    2. 在布局中添加一个ScrollVeiw ,并将“正文”控件包住。

      在这里插入图片描述

    3. 运行

      在这里插入图片描述

      可以看到,视图可以滑动了,点击Web链接时,会启动手机自带的浏览器进行跳转访问。

    69.3 滚动多个元素

    如前所述, ScrollView只能包含一个孩子View(例如article TextView您创建的)。但是,它View可以是另一个ViewGroup包含View元素,例如 LinearLayout. 您可以在中嵌套ViewGroup诸如LinearLayout 类的ScrollView内容,从而滚动 中的所有内容LinearLayout

    1. 向ScrollView中添加一个线性布局

      在这里插入图片描述

    2. 在LinearLayout中移动UI元素

      现在LinearLayout只有一个 UI 元素 - article TextView. 您希望将 包含在article_subheading TextView中,LinearLayout以便两者都滚动。

      在这里插入图片描述

    3. 运行

      现在副标题也可以跟着一起滑~

    69.4 小结
    • 使用 a ScrollView滚动单个子项View(例如 a TextView)。AScrollView只能容纳一个孩子ViewViewGroup.
    • 在a 中使用ViewGroup诸如 LinearLayout子元素来滚动多个元素。将元素包含在.View``ScrollView``View``LinearLayout
    • TextView以粗体和斜体显示带有 HTML 格式标记的自由格式文本。
    • 用作\n自由格式文本中的行尾字符,以防止段落运行到下一个段落。
    • 使用该android:autoLink="web"属性使文本中的 Web 链接可点击。
  • 相关阅读:
    大疆笔试题
    对比分析:GBDT、XGBoost、CatBoost和LightGBM
    网页黑白代码将整个网站(包括子页)变为黑白色
    88. 合并两个有序数组
    Twincat-Simulink 出现问题总结
    Socks5代理、IP代理的关键作用
    Linux服务器清理磁盘
    ichorbio艾美捷CTLA-4体内抗体的应用和相关研究
    齐岳|七甲川染料CY7/CY7.5标记磁性二硫化钨WS2/二氧化锰MnO2/二氧化钛TIO2纳米粒
    2023/8/8 下午10:42:04 objectarx
  • 原文地址:https://blog.csdn.net/weixin_44226181/article/details/126358116