@Partizanin
Java Developer

Как прятать и отображать иконки в RelativeLayout?

есть RelativeLayout в нем несколько чекбоксов с ответами, нужно выбрать один или несколько ответов, после чего нажать кнопку проверить и после нажатия кнопки напротив правильного ответа должна появиться одна иконка а напротив не правильного другая!
Вопрос в том как вообще можно отобразить иконку на RelativeLayout ?
Потом как отобразить ее по нажатию на кнопку ?

вот сам layout
<?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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.apps.partizanin.androidappzno.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/ParagraphLabelValue"
        android:id="@+id/paragraphLabel"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:textSize="15sp"
        android:textIsSelectable="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/paragraphValue"
        android:textSize="15sp"
        android:textIsSelectable="true"
        android:layout_alignTop="@+id/paragraphLabel"
        android:layout_toEndOf="@+id/paragraphLabel"
        android:layout_marginStart="5dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/taskLabel"
        android:textSize="15sp"
        android:textIsSelectable="true"
        android:text="@string/TaskLabelValue"
        android:layout_below="@+id/paragraphLabel"
        android:layout_alignEnd="@+id/paragraphLabel" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/taskValue"
        android:textSize="15sp"
        android:textIsSelectable="true"
        android:layout_alignTop="@+id/taskLabel"
        android:layout_toEndOf="@+id/taskLabel"
        android:layout_marginStart="5dp" />

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New CheckBox"
        android:id="@+id/checkBox2"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/checkBox1"
        android:layout_alignParentLeft="true" />

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New CheckBox"
        android:id="@+id/checkBox1"
        android:layout_below="@+id/paragraphLabel"
        android:layout_alignParentStart="true"
        android:layout_marginTop="196dp" />

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New CheckBox"
        android:id="@+id/checkBox3"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/checkBox2"
        android:layout_alignParentLeft="true" />

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New CheckBox"
        android:id="@+id/checkBox4"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/checkBox3"
        android:layout_alignParentLeft="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/questionText"
        android:layout_below="@+id/paragraphLabel"
        android:layout_marginTop="61dp"
        android:layout_alignEnd="@+id/taskLabel"
        android:layout_toEndOf="@+id/paragraphLabel" />


</RelativeLayout>


вот сама RelativeLayout b224e238026c4bbd9e1f29f49aaf674a.png
  • Вопрос задан
  • 224 просмотра
Решения вопроса 1
gadfi
@gadfi
https://gamega.org
А в чем проблема собсвенно?
Накидайте напротив чекбоксов иконок, сделайте их невидимыми а когда ответят сделайте видимыми, или просто изначально не загружайте картинку а грузите после овтета

upd
видимая
view.setVisibility(View.VISIBLE);
невидимая
view.setVisibility(View.INVISIBLE);
или
view.setVisibility(View.GONE);
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы