인코딩의 Decoding

728x90
반응형

안녕하세요. 이번 글에서는 ScrollView를 구현해 보겠습니다.

ScrollView는 화면을 넘어가는 내용을 다룰때 자동으로 스크롤을 생성해줍니다.

 

+

ScrollView는 하나의 View만을 ScrollView 안에 넣을 수 있습니다.(여러 View를 넣고 싶으면 ScrollView 안에 ViewGroup을 넣어주면 됩니다.)

 

ScrollView 구현하기

1. 프로젝트 생성하기

Start a new Android Studio project 클릭
Empty Activity 선택
App Name은 ScrollApp으로 설정 (다른 것으로 해도 됩니다.)

*오늘 만드는 프로젝트의 전체 구조는 다음과 같습니다.

2. 어플 View를 만져보겠습니다 activiy_main.xml 더블 클릭 --> text 모드로 들어갑니다.

ConstraintLayout을 RelativeLayout으로 바꿔줍니다.

빨간 선으로 표시한 ConstraintLayout을 RelativeLayout으로 바꿔줍니다.

또한 xmlns:app="http://~~"도 지워줍니다 ( ConstraintLayout과 관련된 라인입니다.)

우선 ScrollView 위에 header와 SubHeader을 추가해보겠습니다.

기존에 있던 TextView 위에 다음과 같이 TextVIew 두개를 추가해줍니다.

기존에 있던 TextView 위에 다음과 같이 두개의 TextVIew를 추가해줍니다.

 

3. 프로젝트를 처음 생성할 당시 존재하던 TextView를 다음과 같이 수정합니다. ( ScrollView 안에 넣을 TextView로 수정할 예정)

빨간 선으로 표시된 부분을 지워주고( ConstraintLayout과 관련) 아래 그림과 같이 수정해줍니다.

 

android:text 부분은 string.xml에 내용을 등록하고 연동하여 사용해 보겠습니다.

일단 res > values > string.xml을 열고 다음 내용을 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 Be</i> 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. 28</i>, 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 Shadow</i></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 Bonnie</i></b> and <b><i>Ain’t She Sweet</i></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>Searchin</i></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 Do</i></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 Shout</i></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 Alone</i></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&amp;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 909</i></b> — A song recorded for the <i>Let It Be</i> 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&amp;B feel to it.

 

위의 내용을 <resource> 태그 안에 <string name="article_text">로 지정하고 string 태그 안에 넣어 주면됩니다.

그리고 Android:text 부분을 다음고 같이 바꿔줍니다.

android:text 부분을 @string/article_text 로 수정

그후 가상 Device나 핸드폰에서 프로젝트를 실행 시키면 다음과 같은 화면이 표시됩니다.

아직 ScrollView는 적용이 안된 상태인데요 이제 적용해 보겠습니다.

(만약 String/app_name 부분에 오류가 나면 stirng.xml을 고치면서 지운것이니 string.xml에 

<string name="app_name">ScrollApp</string>을 추가해줍니다.

 

4. ScrollView 추가해주기

다음과 같이 ScrollView 내용에 해당하는 TextView 위 아래에 ScrollView 태그를 넣어줍니다.

* TextView 안에 있던 android:layout_below를 ScrollView 안에 넣어줍니다.

 

<ScrollView> 태그를 다음과 같이 추가해주고 프로젝트를 다시 실행하면 id가 article인 TextView의 내용을 스크롤 할 수 있습니다.

 

+

 

참고

activity_main.xml 전체 코드

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/article_heading"
    android:background="@color/colorPrimary"
    android:textColor="@android:color/white"
    android:padding="10dp"
    android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
    android:textStyle="bold"
    android:text="Header">
  </TextView>
  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/article_subheading"
    android:layout_below="@id/article_heading"
    android:padding="10dp"
    android:textAppearance="@android:style/TextAppearance.DeviceDefault"
    android:text="SubHeader">
  </TextView>

  <ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/article_subheading"
    >
  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/article_text"
    android:id="@+id/article"
    android:lineSpacingExtra="5sp"
    android:padding="10dp"
    />
  </ScrollView>

</RelativeLayout>

string.xml 전체 코드

<resources>
  <string name="app_name">ScrollApp</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 Be</i> 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. 28</i>, 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 Shadow</i></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 Bonnie</i></b> and <b><i>Ain’t She Sweet</i></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>Searchin</i></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 Do</i></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 Shout</i></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 Alone</i></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&amp;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 909</i></b> — A song recorded for the <i>Let It Be</i> 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&amp;B feel to it.
</string>
</resources>

 

봐주셔서 감사합니다!!

반응형

이 글을 공유합시다

facebook twitter googleplus kakaoTalk kakaostory naver band