Android Studio, problem with the Activity

0

I'm new with this from Android, the problem is that after installing it and starting a new project, by going to the activities window they appear with nothing in them, not even the "Hello World" and when I add a button does not appear and throws me the following problem

Thanks for your help.

    
asked by Kenneth Álvarez 09.07.2018 в 03:19
source

2 answers

0

The problem can be for several reasons:

First . Add the library as a dependency in the same build.gradle file.

implementation 'com.android.support.constraint:constraint-layout:1.1.2'

Second . Add restrictions to your views. Example:

app:layout_constraintLeft_toLeftOf="parent"

Third . Click on any widget in your component palette (Button, EditText, TextView, etc ...) and then right click on it, in the option called Constraint Layout , select Infer constraints .

Fourth . Have your XML correctly to use Constraint Layout , Example:

<android.support.constraint.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">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

If none of this works then, it will be changed to LinearLayout or any other.

    
answered by 09.07.2018 / 03:46
source
0

The truth is that we often have this problem and I usually apply the relative layout that can work for you.

  

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

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

    
answered by 09.07.2018 в 11:17