xml Android适合初学者

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xml Android适合初学者相关的知识,希望对你有一定的参考价值。

package com.example.android.htmlquiz;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    int step = 1;
    int correctAnswer = 0;
    int wrongAnswer = 0;

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

    /**
     * Start the quiz showing the first question
     * @param v
     */
    public void startQuiz(View v){
        LinearLayout one = (LinearLayout) findViewById(R.id.start_quiz);
        one.setVisibility(View.GONE);
        LinearLayout question_1 = (LinearLayout) findViewById(R.id.question_1);
        question_1.setVisibility(View.VISIBLE);

    }

    /**
     * Check for answers, increase counters and go to next step
     * @param v
     */
    public void checkQuiz(View v){


        switch(step) {
            case 1:
                RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radio_group_q1);
                if (radioGroup.getCheckedRadioButtonId() == -1) {
                    // no radio buttons are checked
                }
                else {
                    // one of the radio buttons is checked
                    int selectedId = radioGroup.getCheckedRadioButtonId();
                    RadioButton selectedRadioButton = (RadioButton)findViewById(selectedId);
                    String answer = selectedRadioButton.getText().toString();
                    if(answer.equals("Both of the above")) {
                        correctAnswer += 1;
                    } else {
                        wrongAnswer += 1;
                    }

                    LinearLayout question_1 = (LinearLayout) findViewById(R.id.question_1);
                    question_1.setVisibility(View.GONE);
                    LinearLayout question_2 = (LinearLayout) findViewById(R.id.question_2);
                    question_2.setVisibility(View.VISIBLE);
                    step += 1;
                }
                break;
            case 2:
                RadioGroup radioGroup2 = (RadioGroup) findViewById(R.id.radio_group_q2);
                if (radioGroup2.getCheckedRadioButtonId() == -1) {
                    // no radio buttons are checked
                }
                else {
                    // one of the radio buttons is checked
                    int selectedId = radioGroup2.getCheckedRadioButtonId();
                    RadioButton selectedRadioButton = (RadioButton)findViewById(selectedId);
                    String answer = selectedRadioButton.getText().toString();
                    if(answer.equals("All of the above")) {
                        correctAnswer += 1;
                    } else {
                        wrongAnswer += 1;
                    }

                    LinearLayout question_2 = (LinearLayout) findViewById(R.id.question_2);
                    question_2.setVisibility(View.GONE);
                    LinearLayout question_3 = (LinearLayout) findViewById(R.id.question_3);
                    question_3.setVisibility(View.VISIBLE);
                    step += 1;
                }
                break;
            case 3:
                RadioGroup radioGroup3 = (RadioGroup) findViewById(R.id.radio_group_q3);
                if (radioGroup3.getCheckedRadioButtonId() == -1) {
                    // no radio buttons are checked
                }
                else {
                    // one of the radio buttons is checked
                    int selectedId = radioGroup3.getCheckedRadioButtonId();
                    RadioButton selectedRadioButton = (RadioButton)findViewById(selectedId);
                    String answer = selectedRadioButton.getText().toString();
                    if(answer.equals("date")) {
                        correctAnswer += 1;
                    } else {
                        wrongAnswer += 1;
                    }

                    LinearLayout question_3 = (LinearLayout) findViewById(R.id.question_3);
                    question_3.setVisibility(View.GONE);
                    LinearLayout question_4 = (LinearLayout) findViewById(R.id.question_4);
                    question_4.setVisibility(View.VISIBLE);
                    step += 1;
                }
                break;
            case 4:
                RadioGroup radioGroup4 = (RadioGroup) findViewById(R.id.radio_group_q4);
                if (radioGroup4.getCheckedRadioButtonId() == -1) {
                    // no radio buttons are checked
                }
                else {
                    // one of the radio buttons is checked
                    int selectedId = radioGroup4.getCheckedRadioButtonId();
                    RadioButton selectedRadioButton = (RadioButton)findViewById(selectedId);
                    String answer = selectedRadioButton.getText().toString();
                    if(answer.equals("All of the above")) {
                        correctAnswer += 1;
                    } else {
                        wrongAnswer += 1;
                    }

                    LinearLayout question_4 = (LinearLayout) findViewById(R.id.question_4);
                    question_4.setVisibility(View.GONE);
                    LinearLayout question_5 = (LinearLayout) findViewById(R.id.question_5);
                    question_5.setVisibility(View.VISIBLE);
                    step += 1;
                }
                break;
            case 5:
                RadioGroup radioGroup5 = (RadioGroup) findViewById(R.id.radio_group_q5);
                if (radioGroup5.getCheckedRadioButtonId() == -1) {
                    // no radio buttons are checked
                }
                else {
                    // one of the radio buttons is checked
                    int selectedId = radioGroup5.getCheckedRadioButtonId();
                    RadioButton selectedRadioButton = (RadioButton)findViewById(selectedId);
                    String answer = selectedRadioButton.getText().toString();
                    if(answer.equals("All of the above")) {
                        correctAnswer += 1;
                    } else {
                        wrongAnswer += 1;
                    }

                    LinearLayout question_5 = (LinearLayout) findViewById(R.id.question_5);
                    question_5.setVisibility(View.GONE);
                    LinearLayout question_6 = (LinearLayout) findViewById(R.id.question_6);
                    question_6.setVisibility(View.VISIBLE);
                    step += 1;
                }
                break;
            case 6:
                RadioGroup radioGroup6 = (RadioGroup) findViewById(R.id.radio_group_q6);
                if (radioGroup6.getCheckedRadioButtonId() == -1) {
                    // no radio buttons are checked
                }
                else {
                    // one of the radio buttons is checked
                    int selectedId = radioGroup6.getCheckedRadioButtonId();
                    RadioButton selectedRadioButton = (RadioButton)findViewById(selectedId);
                    String answer = selectedRadioButton.getText().toString();
                    if(answer.equals("geolocation.getCurrentPosition()")) {
                        correctAnswer += 1;
                    } else {
                        wrongAnswer += 1;
                    }

                    LinearLayout question_6 = (LinearLayout) findViewById(R.id.question_6);
                    question_6.setVisibility(View.GONE);
                    LinearLayout question_7 = (LinearLayout) findViewById(R.id.question_7);
                    question_7.setVisibility(View.VISIBLE);

                    step += 1;
                }
                break;
            case 7:
                CheckBox a71 = (CheckBox) findViewById(R.id.a71);
                CheckBox a72 = (CheckBox) findViewById(R.id.a72);
                CheckBox a73 = (CheckBox) findViewById(R.id.a73);
                CheckBox a74 = (CheckBox) findViewById(R.id.a74);
                if(a71.isChecked() && a72.isChecked() && a74.isChecked()){
                    correctAnswer += 1;
                } else {
                    wrongAnswer += 1;
                }

                LinearLayout question_7 = (LinearLayout) findViewById(R.id.question_7);
                question_7.setVisibility(View.GONE);
                LinearLayout question_8 = (LinearLayout) findViewById(R.id.question_8);
                question_8.setVisibility(View.VISIBLE);
                step += 1;
                break;
            case 8:
                EditText et = (EditText) findViewById(R.id.missingTag);
                String answer = et.getText().toString();
                if(answer.equals("section")){
                    correctAnswer += 1;
                } else {
                    wrongAnswer += 1;
                }
                LinearLayout question_9 = (LinearLayout) findViewById(R.id.question_8);
                question_9.setVisibility(View.GONE);

                TextView success = (TextView) findViewById(R.id.success);
                success.setText("Correct answers: " + correctAnswer);

                TextView text_result = (TextView) findViewById(R.id.text_result);
                text_result.setText("Your final score is: " + correctAnswer);


                TextView wrong = (TextView) findViewById(R.id.wrong);
                wrong.setText("Wrong answers: " + wrongAnswer);

                LinearLayout final_result = (LinearLayout) findViewById(R.id.final_result);
                final_result.setVisibility(View.VISIBLE);

                Toast.makeText(getApplicationContext(), "Your finale score is; " + correctAnswer, Toast.LENGTH_LONG).show();


                step += 1;
                break;
            default:
                //setContentView(R.layout.default);
        }


    }

    /**
     * Reset status anc counters
     * @param v
     */
    public void restartQuiz(View v){
        /* Reset counters */
        this.step = 1;
        this.correctAnswer = 0;
        this.wrongAnswer = 0;

        /* Reset button status */
        RadioButton rb11 = (RadioButton) findViewById(R.id.a11);
        rb11.setChecked(true);

        RadioButton rb21 = (RadioButton) findViewById(R.id.a21);
        rb21.setChecked(true);

        RadioButton rb31 = (RadioButton) findViewById(R.id.a31);
        rb31.setChecked(true);

        RadioButton rb41 = (RadioButton) findViewById(R.id.a41);
        rb41.setChecked(true);

        CheckBox cb71 = (CheckBox) findViewById(R.id.a71);
        cb71.setChecked(false);

        CheckBox cb72 = (CheckBox) findViewById(R.id.a72);
        cb71.setChecked(false);

        CheckBox cb73 = (CheckBox) findViewById(R.id.a73);
        cb71.setChecked(false);

        CheckBox cb74 = (CheckBox) findViewById(R.id.a74);
        cb71.setChecked(false);

        EditText et = findViewById(R.id.missingTag);
        et.setText("");

        /* Hide results, show first step */
        LinearLayout one = (LinearLayout) findViewById(R.id.start_quiz);
        one.setVisibility(View.VISIBLE);
        LinearLayout final_result = (LinearLayout) findViewById(R.id.final_result);
        final_result.setVisibility(View.GONE);
    }


}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="com.example.android.htmlquiz.MainActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <LinearLayout
            android:id="@+id/start_quiz"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:visibility="visible">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:text="@string/start_quiz"
                android:layout_weight="1.5"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="32dp"
                android:textStyle="bold"
                android:textSize="32sp"
                android:gravity="center_horizontal"
                android:padding="16dp" />
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:adjustViewBounds="true"
                android:maxWidth="250dp"
                android:maxHeight="250dp"
                android:scaleType="centerCrop"
                android:src="@drawable/red_arrow"
                android:layout_gravity="center_vertical|center_horizontal"
                android:contentDescription="@string/start_quiz"
                android:onClick="startQuiz" />
        </LinearLayout>
        <!-- Q1 -->
        <LinearLayout
            android:id="@+id/question_1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:visibility="gone">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/q1"
                android:textSize="24sp"
                android:textStyle="bold"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="32dp"
                android:layout_marginBottom="32dp" />
            <RadioGroup
                android:id="@+id/radio_group_q1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:divider="@color/colorBlack">
                <RadioButton
                    android:id="@+id/a11"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a11"
                    android:checked="true" />
                <RadioButton
                    android:id="@+id/a12"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a12" />
                <RadioButton
                    android:id="@+id/a13"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a13" />
                <RadioButton
                    android:id="@+id/a14"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a14" />
                <Button
                    android:id="@+id/button_check_a1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:background="@color/colorAccent"
                    android:layout_marginTop="32dp"
                    android:tag="1"
                    android:text="@string/next"
                    android:textColor="@color/colorWhite"
                    android:onClick="checkQuiz" />
            </RadioGroup>
        </LinearLayout>
        <!-- Q2 -->
        <LinearLayout
            android:id="@+id/question_2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:visibility="gone">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/q2"
                android:textSize="24sp"
                android:textStyle="bold"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="32dp"
                android:layout_marginBottom="32dp" />
            <RadioGroup
                android:id="@+id/radio_group_q2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:divider="@color/colorBlack">
                <RadioButton
                    android:id="@+id/a21"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a21"
                    android:checked="true" />
                <RadioButton
                    android:id="@+id/a22"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a22" />
                <RadioButton
                    android:id="@+id/a23"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a23" />
                <RadioButton
                    android:id="@+id/a24"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a24" />
                <Button
                    android:id="@+id/button_check_a2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:background="@color/colorAccent"
                    android:layout_marginTop="32dp"
                    android:tag="2"
                    android:text="@string/next"
                    android:textColor="@color/colorWhite"
                    android:onClick="checkQuiz" />
            </RadioGroup>
        </LinearLayout>
        <!-- Q3 -->
        <LinearLayout
            android:id="@+id/question_3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:visibility="gone">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/q3"
                android:textSize="24sp"
                android:textStyle="bold"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="32dp"
                android:layout_marginBottom="32dp" />
            <RadioGroup
                android:id="@+id/radio_group_q3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:divider="@color/colorBlack">
                <RadioButton
                    android:id="@+id/a31"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a31"
                    android:checked="true" />
                <RadioButton
                    android:id="@+id/a32"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a32" />
                <RadioButton
                    android:id="@+id/a33"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a33" />
                <RadioButton
                    android:id="@+id/a34"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a34" />
                <Button
                    android:id="@+id/button_check_a3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:background="@color/colorAccent"
                    android:layout_marginTop="32dp"
                    android:tag="3"
                    android:text="@string/next"
                    android:textColor="@color/colorWhite"
                    android:onClick="checkQuiz" />
            </RadioGroup>
        </LinearLayout>
        <!-- Q4 -->
        <LinearLayout
            android:id="@+id/question_4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:visibility="gone">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/q4"
                android:textSize="24sp"
                android:textStyle="bold"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="32dp"
                android:layout_marginBottom="32dp" />
            <RadioGroup
                android:id="@+id/radio_group_q4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:divider="@color/colorBlack">
                <RadioButton
                    android:id="@+id/a41"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a41"
                    android:checked="true" />
                <RadioButton
                    android:id="@+id/a42"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a42" />
                <RadioButton
                    android:id="@+id/a43"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a43" />
                <RadioButton
                    android:id="@+id/a44"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a44" />
                <Button
                    android:id="@+id/button_check_43"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:background="@color/colorAccent"
                    android:layout_marginTop="32dp"
                    android:tag="4"
                    android:text="@string/next"
                    android:textColor="@color/colorWhite"
                    android:onClick="checkQuiz" />
            </RadioGroup>
        </LinearLayout>
        <!-- Q5 -->
        <LinearLayout
            android:id="@+id/question_5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:visibility="gone">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/q5"
                android:textSize="24sp"
                android:textStyle="bold"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="32dp"
                android:layout_marginBottom="32dp" />
            <RadioGroup
                android:id="@+id/radio_group_q5"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:divider="@color/colorBlack">
                <RadioButton
                    android:id="@+id/a51"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a51"
                    android:checked="true" />
                <RadioButton
                    android:id="@+id/a52"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a52" />
                <RadioButton
                    android:id="@+id/a53"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a53" />
                <RadioButton
                    android:id="@+id/a54"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a54" />
                <Button
                    android:id="@+id/button_check_53"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:background="@color/colorAccent"
                    android:layout_marginTop="32dp"
                    android:tag="5"
                    android:text="@string/next"
                    android:textColor="@color/colorWhite"
                    android:onClick="checkQuiz" />
            </RadioGroup>
        </LinearLayout>
        <!-- Q6 -->
        <LinearLayout
            android:id="@+id/question_6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:visibility="gone">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/q6"
                android:textSize="24sp"
                android:textStyle="bold"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="32dp"
                android:layout_marginBottom="32dp" />
            <RadioGroup
                android:id="@+id/radio_group_q6"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:divider="@color/colorBlack">
                <RadioButton
                    android:id="@+id/a61"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a61"
                    android:checked="true" />
                <RadioButton
                    android:id="@+id/a62"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a62" />
                <RadioButton
                    android:id="@+id/a63"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a63" />
                <RadioButton
                    android:id="@+id/a64"
                    android:layout_width="match_parent"
                    android:layout_height="64dp"
                    android:background="@drawable/custom_divider"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:text="@string/a64" />
                <Button
                    android:id="@+id/button_check_63"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:background="@color/colorAccent"
                    android:layout_marginTop="32dp"
                    android:tag="6"
                    android:text="@string/next"
                    android:textColor="@color/colorWhite"
                    android:onClick="checkQuiz" />
            </RadioGroup>
        </LinearLayout>
        <!-- Q7 -->
        <LinearLayout
            android:id="@+id/question_7"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:visibility="gone">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/q7"
                android:textSize="24sp"
                android:textStyle="bold"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="32dp"
                android:layout_marginBottom="32dp" />
            <CheckBox
                android:id="@+id/a71"
                android:layout_width="match_parent"
                android:layout_height="64dp"
                android:background="@drawable/custom_divider"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:checked="true"
                android:text="@string/a71" />
            <CheckBox
                android:id="@+id/a72"
                android:layout_width="match_parent"
                android:layout_height="64dp"
                android:background="@drawable/custom_divider"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:text="@string/a72" />
            <CheckBox
                android:id="@+id/a73"
                android:layout_width="match_parent"
                android:layout_height="64dp"
                android:background="@drawable/custom_divider"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:text="@string/a73" />
            <CheckBox
                android:id="@+id/a74"
                android:layout_width="match_parent"
                android:layout_height="64dp"
                android:background="@drawable/custom_divider"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:text="@string/a74" />
            <Button
                android:id="@+id/button_check_7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:background="@color/colorAccent"
                android:layout_marginTop="32dp"
                android:tag="7"
                android:text="@string/next"
                android:textColor="@color/colorWhite"
                android:onClick="checkQuiz" />
        </LinearLayout>
        <!-- Q8 -->
        <LinearLayout
            android:id="@+id/question_8"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:visibility="gone">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/q8"
                android:textSize="24sp"
                android:textStyle="bold"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="32dp"
                android:layout_marginBottom="32dp" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:text="@string/missingTag"
                android:padding="24dp"
                android:textSize="16sp"
                android:textStyle="bold"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:textColor="@color/colorWhite"
                android:background="@color/colorAccent"
                android:layout_marginBottom="32dp" />
            <EditText
                android:id="@+id/missingTag"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:hint="@string/missingHint"
                android:maxLines="1" />
            <Button
                android:id="@+id/button_check_8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:background="@color/colorAccent"
                android:layout_marginTop="32dp"
                android:tag="8"
                android:text="@string/next"
                android:textColor="@color/colorWhite"
                android:onClick="checkQuiz" />
        </LinearLayout>
        <!-- Final results -->
        <LinearLayout
            android:id="@+id/final_result"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:visibility="gone">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/done"
                android:textSize="32sp"
                android:textStyle="bold"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="32dp"
                android:layout_marginBottom="16dp" />
            <TextView
                android:id="@+id/text_result"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Final score: 0"
                android:textSize="24sp"
                android:textStyle="bold"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="32dp" />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <TextView
                    android:id="@+id/success"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center_horizontal"
                    android:background="@color/colorSuccess"
                    android:padding="8dp"
                    android:text="Right: "
                    android:textSize="24sp"
                    android:textStyle="bold"
                    android:textColor="@color/colorWhite"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginTop="32dp"
                    android:layout_marginBottom="32dp" />
                <TextView
                    android:id="@+id/wrong"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center_horizontal"
                    android:background="@color/colorFailure"
                    android:padding="8dp"
                    android:text="Wrong: "
                    android:textSize="24sp"
                    android:textStyle="bold"
                    android:textColor="@color/colorWhite"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:layout_marginTop="32dp"
                    android:layout_marginBottom="32dp" />
            </LinearLayout>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:background="@color/colorAccent"
                android:layout_marginTop="32dp"
                android:textColor="@color/colorWhite"
                android:text="@string/restart"
                android:onClick="restartQuiz" />
        </LinearLayout>
    </LinearLayout>
</ScrollView>

以上是关于xml Android适合初学者的主要内容,如果未能解决你的问题,请参考以下文章

有没有适合 Android 开发初学者的 App 源码推荐

有没有适合 Android 开发初学者的 App 源码推荐

有没有适合 Android 开发初学者的 App 源码推荐

有没有适合 Android 开发初学者的 App 源码推荐

制作适用于所有 android 版本的 Ionic Android 应用程序

如何使我的 xml 代码适合所有设备