0

На основной Activity реализовано меню из 7 кнопок. При клике на каждую кнопку открывается отдельное Activity.

Проблема в том, что Activity на которое переходишь не отображает свое содержимое при запуске на реальном устройстве. Вместо этого - белый экран.

Установлен USB-драйвер Google.

Я попытался нажать "Build - Clean Project" и Invalidate Caches.

Это не помогло. В чем проблема?

Main Activity (меню):

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity"
    android:orientation="vertical"
    android:background="@color/tealbg">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:gravity="center"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="15dp"
            android:layout_marginBottom="15dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="44dp"
                android:layout_height="44dp"
                android:layout_marginRight="7dp"
                android:src="@drawable/ic_greetings">

            </ImageView>

            <Button
                android:id="@+id/button1"
                android:background="@drawable/buttonshape"
                android:layout_width="wrap_content"
                android:layout_height="44dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:text="ПРИВЕТСТВИЯ"
                android:textColor="#000000"
                android:textSize="14sp"
                android:stateListAnimator="@null"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="15dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="44dp"
                android:layout_height="44dp"
                android:layout_marginRight="7dp"
                android:src="@drawable/ic_game_info">

            </ImageView>

            <Button
                android:id="@+id/button2"
                android:background="@drawable/buttonshape"
                android:layout_width="wrap_content"
                android:layout_height="44dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:text="ИГРОВАЯ ИНФОРМАЦИЯ"
                android:textColor="#000000"
                android:textSize="14sp"
                android:stateListAnimator="@null"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="15dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="44dp"
                android:layout_height="44dp"
                android:layout_marginRight="7dp"
                android:src="@drawable/ic_thoughts">

            </ImageView>

            <Button
                android:id="@+id/button3"
                android:background="@drawable/buttonshape"
                android:layout_width="wrap_content"
                android:layout_height="44dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:text="ВЫРАЖЕНИЕ МЫСЛЕЙ"
                android:textColor="#000000"
                android:textSize="14sp"
                android:stateListAnimator="@null"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="15dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="44dp"
                android:layout_height="44dp"
                android:layout_marginRight="7dp"
                android:src="@drawable/ic_farewells">

            </ImageView>

            <Button
                android:id="@+id/button4"
                android:background="@drawable/buttonshape"
                android:layout_width="wrap_content"
                android:layout_height="44dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:text="ПРОЩАНИЯ"
                android:textColor="#000000"
                android:textSize="14sp"
                android:stateListAnimator="@null"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="15dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="44dp"
                android:layout_height="44dp"
                android:layout_marginRight="7dp"
                android:src="@drawable/ic_numbers">

            </ImageView>

            <Button
                android:id="@+id/button5"
                android:background="@drawable/buttonshape"
                android:layout_width="wrap_content"
                android:layout_height="44dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:text="ЦИФРЫ/ЧИСЛА"
                android:textColor="#000000"
                android:textSize="14sp"
                android:stateListAnimator="@null"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="15dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="44dp"
                android:layout_height="44dp"
                android:layout_marginRight="7dp"
                android:src="@drawable/ic_abusive_language">

            </ImageView>

            <Button
                android:id="@+id/button6"
                android:background="@drawable/buttonshape"
                android:layout_width="wrap_content"
                android:layout_height="44dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:text="РУГАТЕЛЬСТВА"
                android:textColor="#000000"
                android:textSize="14sp"
                android:stateListAnimator="@null"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="15dp"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginBottom="15dp"
                android:layout_weight="1"
                android:typeface="sans"
                android:textSize="14sp"
                android:textColor="#ffff"
                android:text="Если Вам с трудом даётся общение с англоязычными игроками, то это приложение будет просто находкой для Вас! Коммуникация в CS:GO такая же важная составляющая как точная стрельба или отточенные движения.">
            </TextView>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginBottom="15dp"
                android:layout_weight="1"
                android:typeface="sans"
                android:textSize="14sp"
                android:textColor="#ffff"
                android:text="Слаженная игра в команде - залог практически каждого взятого раунда. Крайне важно уметь давать информацию не только на Великом и Могучем, но и на английском языке.">
            </TextView>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginBottom="15dp"
                android:layout_weight="1"
                android:typeface="sans"
                android:textSize="14sp"
                android:textColor="#ffff"
                android:text="Приложение содержит в себе часто используемые слова и фразы для общения с союзниками.">
            </TextView>
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="15dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="44dp"
                android:layout_height="44dp"
                android:layout_marginRight="7dp"
                android:src="@drawable/ic_about">

            </ImageView>

            <Button
                android:id="@+id/button7"
                android:background="@drawable/buttonshape"
                android:layout_width="wrap_content"
                android:layout_height="44dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:text="О ПРИЛОЖЕНИИ"
                android:textColor="#000000"
                android:textSize="14sp"
                android:stateListAnimator="@null"/>
        </LinearLayout>

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

Пункт меню 1 (в котором не отображается содержимое):

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/tealbg"
    tools:context=".p1">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:gravity="center"
            tools:ignore="UselessParent">

            <Button
                android:id="@+id/button1"
                android:background="@drawable/buttonshape"
                android:layout_width="wrap_content"
                android:layout_height="44dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:text="ПРИВЕТСТВИЯ"
                android:textColor="#000000"
                android:textSize="14sp"
                android:stateListAnimator="@null"
                tools:ignore="HardcodedText"
                tools:targetApi="lollipop" />
        </LinearLayout>

    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

JAVA:

package en.my.voicechat;

import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

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

        final Animation animScale = AnimationUtils.loadAnimation(this, R.anim.scale);
        Button btnScale1 = findViewById(R.id.button1);
        btnScale1.setOnClickListener(view -> view.startAnimation(animScale));

            animScale.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }
                @Override
                public void onAnimationEnd(Animation animScale) {
                    Intent intent = new Intent(MainActivity.this, p1.class);
                    startActivity(intent);
                }
                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });

        Button btnScale2 = findViewById(R.id.button2);
        btnScale2.setOnClickListener(view -> view.startAnimation(animScale));

            animScale.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }
                @Override
                public void onAnimationEnd(Animation animScale) {
                    Intent intent = new Intent(MainActivity.this, p2.class);
                    startActivity(intent);
                }
                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });

        Button btnScale3 = findViewById(R.id.button3);
        btnScale3.setOnClickListener(view -> view.startAnimation(animScale));

            animScale.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }
                @Override
                public void onAnimationEnd(Animation animScale) {
                    Intent intent = new Intent(MainActivity.this, p3.class);
                    startActivity(intent);
                }
                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });

        Button btnScale4 = findViewById(R.id.button4);
        btnScale4.setOnClickListener(view -> view.startAnimation(animScale));

            animScale.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }
                @Override
                public void onAnimationEnd(Animation animScale) {
                    Intent intent = new Intent(MainActivity.this, p4.class);
                    startActivity(intent);
                }
                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });

        Button btnScale5 = findViewById(R.id.button5);
        btnScale5.setOnClickListener(view -> view.startAnimation(animScale));

            animScale.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }
                @Override
                public void onAnimationEnd(Animation animScale) {
                    Intent intent = new Intent(MainActivity.this, p5.class);
                    startActivity(intent);
                }
                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });

        Button btnScale6 = findViewById(R.id.button6);
        btnScale6.setOnClickListener(view -> view.startAnimation(animScale));

            animScale.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }
                @Override
                public void onAnimationEnd(Animation animScale) {
                    Intent intent = new Intent(MainActivity.this, p6.class);
                    startActivity(intent);
                }
                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });

        Button btnScale7 = findViewById(R.id.button7);
        btnScale7.setOnClickListener(view -> view.startAnimation(animScale));

            animScale.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }
                @Override
                public void onAnimationEnd(Animation animScale) {
                    Intent intent = new Intent(MainActivity.this, p7.class);
                    startActivity(intent);
                }
                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });

    }
}

P1 class:

package en.my.voicechat;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class P1 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_p1);
    }
}
8
  • Пожалуйста, уточните вашу конкретную проблему или приведите более подробную информацию о том, что именно вам нужно. В текущем виде сложно понять, что именно вы спрашиваете. 19 фев 2022 в 14:09
  • @Духсообщества Дополнил код 19 фев 2022 в 14:11
  • Скорее всего проблема в классе p1 - покажите его. И переименуйте - классы в Java принято с большой буквы называть, класс с маленькой буквы очень режет глаз.
    – ЮрийСПб
    19 фев 2022 в 16:33
  • 1
    Очень странно. А если что-то в логи вывести из onCreate запускаемой активити - оно в logcat появится? А вообще, кажется, я понял что не так - вы 7 раз меняете слушатель одной и той же анимации. Т.е. по нажатию на любую кнопку вы всегда запускаете активити p7
    – ЮрийСПб
    19 фев 2022 в 17:33
  • 1
    @ЮрийСПб Спасибо! 21 фев 2022 в 11:20

1 ответ 1

0

Вы 7 раз меняете слушатель одной и той же анимации. Т.е. по нажатию на любую кнопку вы всегда запускаете активити p7.

Можно сделать примерно так:

interface AnimationEndListener {
    void onAnimationEnd();
}

private Animation createAnimation(AnimationEndListener animationEndListener) {
    Animation animScale = AnimationUtils.loadAnimation(this, R.anim.scale);
    animScale.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }
        @Override
        public void onAnimationEnd(Animation animScale) {
            animationEndListener.onAnimationEnd();
        }
        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
}

И так использовать:

findViewById(R.id.button1).setOnClickListener(view -> createAnimation(() -> startActivity(new Intent(MainActivity.this, p1.class))));

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.