Showing posts with label ScrollView. Show all posts
Showing posts with label ScrollView. Show all posts

Monday, May 14, 2018

TextView'e Scroll Ekleme

Selam Arkadaşlar;

Andoid Studio'da geliştirdiğimiz projelerde bazı durumlarda oluşturduğumuz TextView'lara scroll eklemek isteyebiliriz. Bu gönderide bu işelmin nasıl yapıldığını anltacağım.

Öncelikle .xml dosyamıza TextView ve ScrollView'ımızı ekliyoruz.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
 <ScrollView
            android:id="@+id/scrollViewCevap"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"
            android:fillViewport="true">

        <TextView
            android:id="@+id/text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18dp"
            android:padding="10dp"
            android:layout_weight="20"
            android:maxLines="10"
            android:background="#FFFFFF"
            android:textStyle="bold"  />
        </ScrollView>

.java dosyamızada aşağıdaki kodları ekliyoruz;

1
2
3
 text1 = (TextView)this.findViewById(R.id.text1);
        text1.setText("Bu kısma istediğiniz text gelecektir");
text1.setMovementMethod(new ScrollingMovementMethod());

Ekran Görüntüsü:

Monday, January 8, 2018

ScrollView Ekleme

Android Studio programında yazdığınız uygulama uzun paragraflar içerebilir ve içerik tek bir sayfada görüntülenemebilir. Bunun için ScrollView kullanmanız gerekmektedir.

ScrollView'i örneklerken, daha ConstraintLayout'un üst kısmına Scrollview için gerekli kodları yazdım. Values kısmından string.xml’e girip LoremIpsum'tan ürettiğim texti oraya kaydettim ve bu text'i XML ekranından çağırdım. Kodlar aşağıdak gibidir.





 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version="1.0" encoding="utf-8"?>
<ScrollView    android:layout_height="match_parent"    
android:layout_width="match_parent"    
xmlns:android="http://schemas.android.com/apk/res/android">

<android.support.constraint.ConstraintLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"    
    android:layout_width="match_parent"    
    android:layout_height="match_parent"    
    tools:context="com.hande.umut.toastmesaj.MainActivity">

    <TextView        android:id="@+id/textmesaj"        
    android:layout_width="wrap_content"        
    android:layout_height="wrap_content"        
    android:text="@string/loremipsum"        
    app:layout_constraintBottom_toBottomOf="parent"        
    app:layout_constraintLeft_toLeftOf="parent"        
    app:layout_constraintRight_toRightOf="parent"        
    app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
</ScrollView>