Как просмотреть только два TextView в Android - PullRequest
0 голосов
/ 09 мая 2018

У меня есть вопросник, в котором я хочу, чтобы пользователь видел только предыдущий и текущий вопрос. Как этого добиться в Android. Это мой вид XML. Пользователь может увидеть максимум два вопроса - предыдущий и текущий. Я использовал RelativeLayout, который содержит ScrollView, и в этом я использую несколько TextView для вопросов и Button для true / false

<?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"
    style="@android:style/Widget.DeviceDefault.Light.ScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:fillViewport="false"
    android:scrollbarStyle="outsideOverlay"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.scanqr_android.ScrollingActivity"
    tools:showIn="@layout/activity_scrolling">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true">

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

            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:background="#3f51b5"
                android:gravity="center_vertical"
                android:paddingLeft="10dp"
                android:text="MY PAGE TITLE"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="#fff" />

            <TextView
                android:id="@+id/textView5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Caterpillars turn into butterflies."
                tools:text="Caterpillars turn into butterflies." />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/button5"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="true" />

                <Button
                    android:id="@+id/button6"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="false" />

            </LinearLayout>

            <TextView
                android:id="@+id/textView9"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Bubble gum contains rubber."
                tools:text="Bubble gum contains rubber." />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/button7"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="true" />

                <Button
                    android:id="@+id/button8"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="false" />
            </LinearLayout>

            <TextView
                android:id="@+id/textView10"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="The deadliest earthquake of 2017 took place in Iran and Iraq." />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/Button9"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="true" />

                <Button
                    android:id="@+id/button10"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="false" />
            </LinearLayout>

            <TextView
                android:id="@+id/textView11"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Electrons are larger than molecules." />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/button11"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="true" />

                <Button
                    android:id="@+id/button12"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="false" />
            </LinearLayout>

            <TextView
                android:id="@+id/textView12"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Thunderstorms have particular sound frequencies that can hurt a dog’s ears." />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/button13"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="true" />

                <Button
                    android:id="@+id/button14"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="false" />
            </LinearLayout>

            <TextView
                android:id="@+id/textView13"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text=" There are 30 days in May." />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/button15"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="true" />

                <Button
                    android:id="@+id/button16"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="false" />
            </LinearLayout>

        </LinearLayout>

    </ScrollView>
</RelativeLayout>

Ответы [ 2 ]

0 голосов
/ 09 мая 2018

Вы просто скрываете текстовое представление вот так

textView.setVisibility(View.INVISIBLE);

или

textView.setVisibility(View.GONE);

Взгляните на это Как настроить видимость TextView?

0 голосов
/ 09 мая 2018

Сначала зарегистрируйте свой layout идентификатор, используя findViewById() в java file. Затем вы можете скрыть макет textviews, используя это -

linearLayout.setVisibility(View.GONE); путем проверки условий.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...