Y
Y
ywitodenasuby2020-10-04 12:40:17
Android
ywitodenasuby, 2020-10-04 12:40:17

Visibility=gone doesn't work in xml why?

If I create a TextView in xml and specify android:visibility="gone" in the same place, then after launching the TextView it is still displayed. Why?

<?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">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:visibility="gone" />

</androidx.constraintlayout.widget.ConstraintLayout>


public class MainActivity extends AppCompatActivity {

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

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Pavlov, 2020-10-04
@ywitodenasuby

The attributes of the root tag of the xml file specify the pluggable namespaces. In your case:

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"

The namespace toolsis just what you need to change the view only in the editor. Use android:visibility="gone"to completely change the display TextView.
Android Studio displays a key icon next to "editor only" values.
5f7a36e063090850719004.png

O
Oleg Carp, 2020-10-04
@Rebel-Cat

Everything is correct here, it was worth attaching the code,
try to add it programmatically and remove it from xml:

TextView kelErechApaim;
kelErechApaim = findViewById(R.id.kelErechApaim);
 kelErechApaim.setVisibility(View.GONE);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question