Home > OS >  Androi studio layout bug
Androi studio layout bug

Time:09-22

Hello im trying to put a TextView in my app, but when i drag it this happens. Ive added the style and layout xmls

Please forgive me if there is any newbie errors, im kinda new to this

enter image description here

My theme.xml file:

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->

    <style name="AppTheme" parent="@style/Theme.AppCompat.DayNight.NoActionBar" />

    <style name="AppBgTheme" parent="@style/AppTheme">
        <item name="android:windowBackground">@drawable/launcher_bg</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:navigationBarColor">@android:color/transparent</item>
        <item name="android:fontFamily">sans-serif-medium</item>
    </style>

    <style name="RobotoTextViewStyle" parent="@android:style/Widget.TextView">
        <item name="android:fontFamily">sans-serif-light</item>
    </style>

    <style name="Platform.ThemeOverlay.AppCompat.Dark" parent="@style/Platform.ThemeOverlay.AppCompat" />
    <style name="Platform.ThemeOverlay.AppCompat.Light" parent="@style/Platform.ThemeOverlay.AppCompat" />
</resources>

layout xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:tools="http://schemas.android.com/tools"
    android:layout_gravity="center"
    android:id="@id/activity_main"
    android:padding="6.0dip"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">


    <TextView
        android:id="@ id/textView111"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_name"
        android:textColor="#00AAFF"
        android:textSize="36sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.442" />
</androidx.constraintlayout.widget.ConstraintLayout>

CodePudding user response:

added a next to id in @id/activity_main which indicates that this id isn't identified yet and it's the first time to mention.

<?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_gravity="center"
    android:id="@ id/activity_main"
    android:padding="6.0dip"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >


    <TextView
        android:id="@ id/textView111"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_name"
        android:textColor="#00AAFF"
        android:textSize="36sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.442" />
</androidx.constraintlayout.widget.ConstraintLayout>

if that doesn't solve your problem, check your build.gradle(Module:app) may be you didn't add the androidx constraint layout dependency and that's why your layout doesn't recognize it.

dependencies {
...
    implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
...
}
  • Related