2016-04-25 6 views
0

Мне нужно много текста в моем приложении, и до сих пор текст просто останавливается в нижней части экрана. Это не прокручивается, поэтому мне нужна прокрутка на моей странице. Теперь я понял, что это просто что-то похожее на то, чтобы положить Scrollview в ваш activity_main.xml, но это пока не сработало.Добавление ScrollView

Текст сам по себе помещен в мой strings.xml, текст в моей активности_mains. Это код для моего MainActivity:

package com.example.rodekruis; 

import android.net.Uri; 
import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.text.Html; 
import android.text.Spanned; 
import android.text.method.LinkMovementMethod; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.Button; 
import android.widget.TextView; 

public class ContactActivity extends Activity { 


    TextView HyperLink; 
    Spanned Text; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_contact); 







    } 




} 

Это мой activity_main код:

<LinearLayout 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" 
    android:orientation="vertical" 
    tools:context="com.example.rodekruis.Bezoek" > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left" 
     android:layout_marginBottom="20dp" 
     android:src="@drawable/rkz_logo" 
     android:layout_marginLeft="38dp" /> 


    <ScrollView 
    android:id="@+id/scrollview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="350dp" 
     android:orientation="vertical" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="244dp" 
     android:layout_height="276dp" 
     android:layout_gravity="center" 
     android:text="@string/title_activity_contact" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="@color/black" /> 


</LinearLayout> 

</ScrollView> 
</LinearLayout> 

Вот как это выглядит в графической схеме. Текст останавливается на полпути, я не могу прокрутить вниз.

enter image description here

+1

Изменить Внутренний 'LinearLayout' Высота от статического до' Match_Parent'. –

+0

нет, не match_parent, но wrap_content ... а также TextView должен иметь wrap_content как высоту ... так что @NicolasSimon - правильный ответ – Selvin

+0

, он показывает, как он должен, поскольку вы указали ширину и высоту фиксированного размера. Отнеситесь к 'wrap_content' –

ответ

1

Просто измените макет следующим образом:

<LinearLayout 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" 
android:orientation="vertical" 
tools:context="com.example.rodekruis.Bezoek" > 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="left" 
    android:layout_marginBottom="20dp" 
    android:src="@drawable/rkz_logo" 
    android:layout_marginLeft="38dp" /> 


    <ScrollView 
    android:id="@+id/scrollview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="244dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="@string/title_activity_contact" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="@color/black" /> 
    </ScrollView> 
</LinearLayout> 
+1

Спасибо, что сделали это ! Цените это много –

0

Попробуйте изменить высоту scrollview к wrap_content так:

<ScrollView 
    android:id="@+id/scrollview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    > 
+0

серьезно? 'wrap_content' для высоты' 'ScrollView '' не имеет большого значения ... в таком случае' ScrollView' занимает высоту от внутреннего вида и делает ее независящей (потому что только что-то большее в чем-то меньшем прокручивается) – Selvin

0

Попробуйте это в Scroll View.

android:nestedScrollingEnabled="true" 
0

попробуйте что-то вроде этого ... вы ограничиваете размер в scrollview вместо текста.

<ScrollView 
    android:id="@+id/scrollview" 
    android:layout_width="244dp" 
    android:layout_height="276dp" 
    > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:text="@string/title_activity_contact" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="@color/black" /> 

</ScrollView> 
Смежные вопросы