How to make a ScrollView with several components?

0

I'm trying to make an activity of a project of mine contain a considerable amount of components.

I tried doing this using a ScrollingActivity that contained more than just the "default" textView (the one that already comes when it is created), but I discovered that it is not possible, at least as far as I know.

My activity basically contains this template:

Butasyoumightimagine,itdoesnotcontainjustthesetwoquestions.

IalsotriedaScrollView,butIshouldnothavedonethesameinthecorrectwayoritsimplyhasalimitationofnotbeingableto"exceed" the layout limit.

I would like to know how to put all this in activity:

WiththeimageIwantedtoexpressthatthecontentIwanttoaddgoesbeyondit,tothepointthatIwasnotabletouseaScrollView.

Imadeacodetemplate(onlywiththefirsttwobuttons,questionsandanswers)incaseitisusefulforabetterunderstandingand/orresponse:

MainActivity:

package genesysgeneration.chinterative;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Button btnSim01, btnSim02, btnNao01, btnNao02;
    private TextView tvPergunta01, tvPergunta02, tvResposta01, tvResposta02;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnSim01=(Button)findViewById(R.id.btnSim01);
        btnSim02=(Button)findViewById(R.id.btnSim02);
        btnNao01=(Button)findViewById(R.id.btnNao01);
        btnNao02=(Button)findViewById(R.id.btnNao02);

        tvPergunta01=(TextView)findViewById(R.id.tvPergunta01);
        tvPergunta02=(TextView)findViewById(R.id.tvPergunta02);
        tvResposta01=(TextView)findViewById(R.id.tvResposta01);
        tvResposta02=(TextView)findViewById(R.id.tvResposta02);

    }

    public void onClick(View v){

        switch (v.getId()){
            
            case R.id.btnSim01:
                
                break;
            
            case R.id.btnNao01:
                
                break;
            
            case R.id.btnSim02:
                
                break;
            
            case R.id.btnNao02:
                
                break;
            
        }
        
    }

}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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="genesysgeneration.chinterative.MainActivity">

    <TextView
        android:id="@+id/tvPergunta01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pergunta 1" />

    <TextView
        android:id="@+id/tvResposta01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/tvPergunta01"
        android:layout_marginTop="104dp"
        android:text="texto com a resposta baseada na escolha do button " />

    <TextView
        android:id="@+id/tvPergunta02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        android:text="pergunta 2" />

    <Button
        android:id="@+id/btnSim01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/tvPergunta01"
        android:layout_marginTop="26dp"
        android:text="sim" />

    <Button
        android:id="@+id/btnNao01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/btnSim01"
        android:text="nao" />

    <Button
        android:id="@+id/btnSim02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/btnSim01"
        android:layout_alignRight="@+id/btnSim01"
        android:layout_below="@+id/tvPergunta02"
        android:layout_marginTop="68dp"
        android:text="sim" />

    <Button
        android:id="@+id/btnNao02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/btnNao01"
        android:layout_alignStart="@+id/btnNao01"
        android:layout_alignTop="@+id/btnSim02"
        android:text="nao" />

    <TextView
        android:id="@+id/tvResposta02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/btnSim02"
        android:layout_marginTop="46dp"
        android:text="texto com a resposta baseada na escolha do button " />

</RelativeLayout>
    
asked by anonymous 25.03.2017 / 00:18

1 answer

0

In this question about # has an answer that can solve your problem. Basically you should use ScrollView this way below. See:

<ScrollView 
    ...
    ...
    <RelativeLayout
        ...
        ...

    </RelativeLayout>
</ScrollView>

Then your activity_main.xml file should look like this:

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

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

        <TextView
            android:id="@+id/tvPergunta01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Pergunta 1" />

        <TextView
            android:id="@+id/tvResposta01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/tvPergunta01"
            android:layout_marginTop="104dp"
            android:text="texto com a resposta baseada na escolha do button " />

        <TextView
            android:id="@+id/tvPergunta02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:text="pergunta 2" />

        <Button
            android:id="@+id/btnSim01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/tvPergunta01"
            android:layout_marginTop="26dp"
            android:text="sim" />

        <Button
            android:id="@+id/btnNao01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/btnSim01"
            android:text="nao" />

        <Button
            android:id="@+id/btnSim02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignEnd="@+id/btnSim01"
            android:layout_alignRight="@+id/btnSim01"
            android:layout_below="@+id/tvPergunta02"
            android:layout_marginTop="68dp"
            android:text="sim" />

        <Button
            android:id="@+id/btnNao02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/btnNao01"
            android:layout_alignStart="@+id/btnNao01"
            android:layout_alignTop="@+id/btnSim02"
            android:text="nao" />

        <TextView
            android:id="@+id/tvResposta02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/btnSim02"
            android:layout_marginTop="46dp"
            android:text="texto com a resposta baseada na escolha do button " />

    </RelativeLayout>
</ScrollView>
    
25.03.2017 / 19:09