Study/Android

T01.03-Exercise-AddScrolling

nobang 2019. 1. 6. 11:30
728x90

EX1 : 프로젝트 생성, Textview 추가

EX2 : TextView에 내용 넣기


ToyList를 보면 수 많은 장난감이 있으나 실제 보이는 장남감 갯수는 처음 몇 개 뿐이다.


화면길이를 넘어가기 때문인데

이 경우 ScrollView로 감싸주면 해결된다.


TODO 확인


<!--TODO (1) Add a ScrollView around the TextView so you can scroll through the list of toys-->

ScrollView로 TextView를 감싼다.

<ScrollView
        android:layout_width=""
        android:layout_height="">
        <TextView...>
</ScrollView>


<!--TODO (2) Make the width of the ScrollView match_parent and the height wrap_content-->

ScrollView내 속성을 width=match_parent, height=wrap_content 로 한다.


<ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


전체 소스

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_toy_names"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:padding="16dp"
android:textSize="20sp" />
</ScrollView>
</FrameLayout>


실행해보면 Scroll이되어 모든 장난감 목록을 볼 수 있다.


728x90