Come utilizzare ScrollView in Android?

Ho un file di layout XML, ma il text è più che adatto alla dimensione dello schermo. Cosa devo fare per fare un ScrollView ?

 <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1" > <TableRow> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dip" android:layout_marginTop="10dip" android:layout_marginRight="5dip" android:tint="#55ff0000" android:src="@drawable/icon" /> </TableRow> <TableRow> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Name " /> <TextView android:id="@+id/name1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Veer" /> </TableRow> <TableRow> <TextView android:id="@+id/age" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Age" /> <TextView android:id="@+id/age1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="23" /> </TableRow> <TableRow> <TextView android:id="@+id/gender" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Gender" /> <TextView android:id="@+id/gender1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Male" /> </TableRow> <TableRow> <TextView android:id="@+id/profession" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Professsion" /> <TextView android:id="@+id/profession1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Mobile Developer" /> </TableRow> <TableRow> <TextView android:id="@+id/phone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Phone" /> <TextView android:id="@+id/phone1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="03333736767" /> </TableRow> <TableRow> <TextView android:id="@+id/email" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Email" /> <TextView android:id="@+id/email1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="veer.developer@gmail.com" /> </TableRow> <TableRow> <TextView android:id="@+id/hobby" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Hobby" /> <TextView android:id="@+id/hobby1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Play Games" /> </TableRow> <TableRow> <TextView android:id="@+id/ilike" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" I like" /> <TextView android:id="@+id/ilike1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Java, Objective-c" /> </TableRow> <TableRow> <TextView android:id="@+id/idislike" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" I dislike" /> <TextView android:id="@+id/idislike1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Microsoft" /> </TableRow> <TableRow> <TextView android:id="@+id/address" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Address" /> <TextView android:id="@+id/address1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Johar Mor" /> </TableRow> </TableLayout> 

  • Singleton di attività Android
  • maxWidth non funziona con fill_parent
  • Android: logging di audio utilizzando la riproduzione della class di audiocorde in avanti
  • pila di sorso per il iphone e android
  • Filtra l'output in logcat da tagname
  • Ottimizzazioni Java: (Hotspot / Dalvik) Ottimizzazione del metodo finale che restituisce una costante?
  • Il modo migliore per aggiornare TextView, each minuto, al minuto
  • SPAN_EXCLUSIVE_EXCLUSIVE non può avere un errore di lunghezza zero each volta che un editText diventa vuoto
  • Crea e visualizza la mappa interna su Android
  • RxJava - Combinazione di più o diverse chiamate di servizio web
  • Android, riguardo al design dell'interface utente
  • Come visualizzare le immagini animate in android?
  • 7 Solutions collect form web for “Come utilizzare ScrollView in Android?”

    Basta fare un layout di livello superiore a ScrollView:

     <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> <TableLayout android:layout_width="match_parent" android:layout_height="match_parent" android:stretchColumns="1"> <!-- everything you already have --> </TableLayout> </ScrollView> 

    Ci sono due opzioni. Puoi rendere il tuo integer layout scrollabile o solo il TextView essere scrollabile.

    Per il primo caso,

     <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" > <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1" > <TableRow> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dip" android:layout_marginRight="5dip" android:layout_marginTop="10dip" android:src="@drawable/icon" android:tint="#55ff0000" > </ImageView> </TableRow> <TableRow> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Name " > </TextView> <TextView android:id="@+id/name1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Veer" > </TextView> </TableRow> <TableRow> <TextView android:id="@+id/age" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Age" > </TextView> <TextView android:id="@+id/age1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="23" > </TextView> </TableRow> <TableRow> <TextView android:id="@+id/gender" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Gender" > </TextView> <TextView android:id="@+id/gender1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Male" > </TextView> </TableRow> <TableRow> <TextView android:id="@+id/profession" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Professsion" > </TextView> <TextView android:id="@+id/profession1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Mobile Developer" > </TextView> </TableRow> <TableRow> <TextView android:id="@+id/phone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Phone" > </TextView> <TextView android:id="@+id/phone1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="03333736767" > </TextView> </TableRow> <TableRow> <TextView android:id="@+id/email" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Email" > </TextView> <TextView android:id="@+id/email1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="veer.developer@gmail.com" > </TextView> </TableRow> <TableRow> <TextView android:id="@+id/hobby" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Hobby" > </TextView> <TextView android:id="@+id/hobby1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Play Games" > </TextView> </TableRow> <TableRow> <TextView android:id="@+id/ilike" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" I like" > </TextView> <TextView android:id="@+id/ilike1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Java, Objective-c" > </TextView> </TableRow> <TableRow> <TextView android:id="@+id/idislike" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" I dislike" > </TextView> <TextView android:id="@+id/idislike1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Microsoft" > </TextView> </TableRow> <TableRow> <TextView android:id="@+id/address" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:text=" Address" > </TextView> <TextView android:id="@+id/address1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Johar Mor" > </TextView> </TableRow> <Relativelayout> </Relativelayout> </TableLayout> </RelativeLayout> </ScrollView> 

    o, come ho detto, puoi utilizzare scrollView per TextView da sola.

    Uno ScrollView è un tipo speciale di FrameLayout in quanto consente agli utenti di scorrere un elenco di viste che occupano più spazio rispetto a quello fisico. Aggiungo solo alcuni attributi.

     <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" android:scrollbars = "vertical" android:scrollbarStyle="insideInset" > <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1" > <!-- Add here which you want --> </TableLayout> </ScrollView> 

    Come detto in precedenza è ansible inserirlo all'interno di uno ScrollView … e se si desidera che la visualizzazione di scorrimento sia orizzontale inserirla all'interno di HorizontalScrollView … e se si desidera che il componente (o layout) sia supportto entrambi inseriti all'interno di entrambi come questo :

      <HorizontalScrollView> <ScrollView> <!-- SOME THING --> </ScrollView> </HorizontalScrollView> 

    e con l'impostazione del layout_width e del layout_height .

    Inserisci il tuo TableLayout all'interno di un layout ScrollView. Quello risolverà il tuo problema.

    Per scorrere i dati nella visualizzazione di text è ansible utilizzarlo nella visualizzazione di text. e aggiungere e per qualsiasi altro layout è ansible aggiungere semplicemente la vista di scorrimento sul layout come le persone stanno dicendo sopra.

    / ** android: scrollable = true a textview nel layout xml.

     TextView txtScroll = (TextView) findViewById(R.id.txt1); txtScroll.setMovementMethod(new ScrollingMovementMethod()); 

    * //

     <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1" > <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioGroup android:layout_width="fill_parent" android:layout_height="match_parent" > <RadioButton android:id="@+id/butonSecim1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight=".50" android:text="@string/buton1Text" /> <RadioButton android:id="@+id/butonSecim2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight=".50" android:text="@string/buton2Text" /> </RadioGroup> </TableRow> <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TableLayout android:id="@+id/bilgiAlani" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="invisible" > <TableRow android:id="@+id/BilgiAlanitableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/bilgiMesaji" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight=".100" android:ems="10" android:gravity="left|top" android:inputType="textMultiLine" /> </TableRow> </TableLayout> </TableRow> <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/metin4" android:layout_height="match_parent" android:layout_weight=".100" android:text="deneme" /> </TableRow> <TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/metin5" android:layout_height="match_parent" android:layout_weight=".100" android:text="deneme" /> </TableRow> </TableLayout> </ScrollView> 
    L'Android è un fan Android di Google, tutto su telefoni Android, Android Wear, Android Dev e applicazioni Android Games e così via.