Скрытие всех текстовых представлений в Android Studio с белым изображением - PullRequest
3 голосов
/ 11 июля 2020

Я пытаюсь скрыть все содержимое моего экрана на 10 секунд белым изображением, но кажется, что текст появляется поверх белого изображения, несмотря ни на что. Есть ли способ скрыть textView (или любые другие изображения imageView в будущем) с помощью белого изображения? Спасибо!

Вот мой основной класс деятельности:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
     final ImageView splash = findViewById(R.id.imageView);
    splash.setScaleType(ImageView.ScaleType.FIT_XY);
    splash.postDelayed(new Runnable() {
        @Override
        public void run() {
            splash.setVisibility(View.GONE);
        }
    }, 10000);
}}

Вот мой XML файл:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    android:textSize="24sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.544"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/white" />

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="172dp"
    android:layout_marginTop="268dp"
    android:text="TextToHide"
    android:textSize="36sp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

enter image description here

введите описание изображения здесь

1 Ответ

2 голосов
/ 11 июля 2020

Если вы хотите, чтобы ImageView был на TextView, вам нужно сначала добавить к XML TextView, а затем ImageView, например:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    android:textSize="24sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.544"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />


<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="172dp"
    android:layout_marginTop="268dp"
    android:text="TextToHide"
    android:textSize="36sp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/white" />

Теперь ваш TextView будет позади ImageView

Я не знаю, что вы хотите сделать, но я думаю, что будет проще установить TextView видимость на GONE или INVISIBLE, чем ставить ImageView на контент что Вы хотите скрыть.

...