简体   繁体   中英

Using a scrollview?

I use scrollView in my project. There are some questions in textview and answers of question in radioButton. I should add horizontal scrollBar to this layout to show more questions in Activity . But scrollview doesn't work. Also I can't add scrollBar there, that seem doesn't work. I just looked some questions in StackOverflow. According them my codes should work. But it doesn't work. Please help me.

job_security.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">
<LinearLayout
    android:id="@+id/radio_layout"
    android:layout_width="match_parent"
    android:layout_height="222dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:orientation="vertical">
    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scrollbars="vertical">

        <TextView
            android:id="@+id/textView4"
            android:layout_width="360dp"
            android:layout_height="26dp"
            android:layout_marginTop="20dp"
            android:text="@string/job_security_question1"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/job_security_question1.2"
            android:textSize="12sp" />


        <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/rd1_yes"
                android:layout_width="190dp"
                android:layout_height="match_parent"
                android:buttonTint="@color/colorPrimary"
                android:gravity="left|center_vertical"
                android:text="@string/radio_yes" />

            <RadioButton
                android:id="@+id/rd1_no"
                android:layout_width="190dp"
                android:layout_height="match_parent"
                android:buttonTint="@color/colorPrimary"
                android:text="@string/radio_no" />
        </RadioGroup>

        <TextView
            android:id="@+id/textView6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="@string/job_security_question2" />

        <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/rd2_yes"
                android:layout_width="190dp"
                android:layout_height="match_parent"
                android:buttonTint="@color/colorPrimary"
                android:gravity="left|center_vertical"
                android:text="@string/radio_yes" />

            <RadioButton
                android:id="@+id/rd2_no"
                android:layout_width="190dp"
                android:layout_height="match_parent"
                android:buttonTint="@color/colorPrimary"
                android:text="@string/radio_no" />
        </RadioGroup>
    </ScrollView>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp">

        <Button
            android:id="@+id/btn_login"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="178dp"
            android:layout_height="40dip"
            android:layout_centerHorizontal="true"
            android:background="@drawable/buton_radious"
            android:clickable="true"
            android:focusable="true"
            android:text="@string/send_button"
            android:textColor="@android:color/white"
            android:textSize="14sp" />
    </RelativeLayout>
</LinearLayout>

Inside ScrollView must contain only one layout!

This sample code solve your problem

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

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

     <!-- here add your views -->

   </LinearLayout>
</ScrollView>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM