My text views aren't appearing when running the app. I've tried adjusting the visibility and elevation. I've looked online and none of the answers worked.
How do I fix this? (Java)
This is the render in android studio
This is the emulator, my physical phone shows the same thing
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
android:background="#color/cardview_light_background"
android:elevation="-1dp"
android:theme="#style/ThemeOverlay.GrubhubWheel.FullscreenContainer">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ImageButton
android:id="#+id/gear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#android:color/transparent"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_settings_5672"
tools:ignore="SpeakableTextPresentCheck" />
<TextView
android:id="#+id/Blind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/yaro_st"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.AppCompat.Display3"
android:textColor="#010101"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Blind" />
<TextView
android:id="#+id/Ate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:fontFamily="#font/galano_grotesque_alt_semi_bold"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.AppCompat.Display4"
android:textColor="#4ca66c"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/Blind"
tools:text="Ate" />
<ImageButton
android:id="#+id/wheel"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginVertical="10dp"
android:backgroundTint="#android:color/transparent"
android:elevation="-1dp"
android:forceHasOverlappingRendering="true"
android:rotation="15"
android:scaleType="fitCenter"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Ate"
app:layout_constraintVertical_bias="0.85"
app:srcCompat="#drawable/random_wheel"
tools:ignore="SpeakableTextPresentCheck,ImageContrastCheck" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
Related
I want to put the bottom navigation menu with my recyclerview at the bottom of the view. It is currently at the top and I need help sending it to the bottom.
This is how it look now:
This is my xml code:
<?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:id="#+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Oficinas Credenciadas"
android:textColor="#android:color/black"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/listRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="1dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleTextView" />
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_constraintTop_toBottomOf="#+id/titleTextView"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/botton_nav_menu"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
Add
app:layout_constraintBottom_toBottomOf="parent"
To bottom navigation item so code will be like that
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="#menu/botton_nav_menu"
tools:ignore="MissingConstraints" />
I have made some changes and this is how it the items are positioned now.
This is how the code looks now. If this helps you, an upvote would be appreciated. Thanks
<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">
<TextView
android:id="#+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Oficinas Credenciadas"
android:textColor="#android:color/black"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/listRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="1dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
app:layout_constraintBottom_toTopOf="#+id/bottom_menu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleTextView" />
<!-- NOT SURE WHY YOU HAVE THE FRAMELAYOUT AND RECYCLERVIEW OCCUPYING THE SAME SPACE BUT IF YOU INTEND TO HIDE AND SHOW THEM AT DIFFERENT TIMES, I HAVE IMPROVED THEIR CONSTRAINTS -->
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_constraintBottom_toTopOf="#+id/bottom_menu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleTextView"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/sample_menu"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
I am using Fragment in my app. I try to put a Button top of layout but it does not go to top of the layout.
This is my xml of Fragment :
<?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=".ui.home.HomeFragment">
<Button
android:id="#+id/zirai"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="ZİRAİ"
android:textColor="#color/white"
android:textSize="20sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/döviz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:text="DÖVİZ"
android:textColor="#color/white"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/text_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="290dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
it looks like this :
I need to put that two button top of the layout
How I can solve this issue
Thanks
You probably have a padding or margin attribute in your activity's xml file. Find;
android:paddingTop="?attr/actionBarSize"
or
android:marginTop="?attr/actionBarSize"
and remove them.
I have to delete images from recyclerview, so for that, I'm added one delete button at the top right corner of the cardview. But in some cards that delete button is positioned properly and in some cards it is not.
Here is my XML file code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cardview"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp">
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageview"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:src="#drawable/android"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:text="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imageview"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/imageview" />
<ImageButton
android:id="#+id/bt_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_delete" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
Below is the output
Here delete button is not displayed properly in the top three cards but it is displayed properly at bottom cards
It is also displayed properly in portrait mode:
Please tell me what I have to do in order to solve this problem
The inner ConstraintLayout has
android:layout_width="wrap_content"
Should be
android:layout_width="match_parent"
See if this helps:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cardview"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageview"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:src="#mipmap/ic_launcher"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:text="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imageview"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/imageview" />
<ImageButton
android:id="#+id/bt_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#mipmap/ic_launcher" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
I am trying to create a game like tic tac toe by using the GridLayout. The preview screen could display the background picture for the GridLayout (the board) but could not display the imageView that I inserted in the GridLayout (the red O). There is also an error in the message box that said:
java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener
I have tried to refresh the layout and rebuild the project but still cannot fix the error.
The preview screen compare to the emulator screen where the two images are displayed
The code for the activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity">
<android.support.v7.widget.GridLayout
android:layout_width="368dp"
android:layout_height="368dp"
android:background="#drawable/board"
app:columnCount="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:rowCount="3">
<ImageView
android:id="#+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
app:srcCompat="#drawable/red" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
app:srcCompat="#drawable/red" />
</android.support.v7.widget.GridLayout>
</android.support.constraint.ConstraintLayout>
Try this code and change only GridLayout take.. you can change root layout instand of constraintLayout take any layout.
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity">
<GridLayout
android:layout_width="368dp"
android:layout_height="368dp"
android:columnCount="3"
android:rowCount="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
android:src="#drawable/user" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
android:src="#drawable/user" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
android:src="#drawable/user" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
android:src="#drawable/user" />
</GridLayout>
set orientation for grid layout
<GridLayout
android:columnCount="3"
android:rowCount="3"
android:orientation="horizontal"
/>
Just change your <android.support.v7.widget.GridLayout
<GridLayout
android:layout_width="368dp"
android:layout_height="368dp"
android:background="#drawable/board"
android:columnCount="3"
android:rowCount="3"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
app:srcCompat="#drawable/red" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
app:srcCompat="#drawable/red" />
</GridLayout>
This showing preview for me. Try this.
Also check dependency library version
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
In my Android Studio your xml is both showing in preview and emulator. Try to do following.
1) Add to you build.gradle(Module.app) these dependencies again
implementation 'com.android.support:gridlayout-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
2) After successfully importing dependencies, refresh the Android Studio
Hope it works!
For those who stumble upon this error. Change android.support.v7.widget.GridLayout to GridLayout only in the XML. I had the same issue and this was the solution.
I've created a simple activity design using ConstraintLayout.
Whenever I try to center a textView, it does it correctly in the blueprints but never does it in the actual app. Not sure if i am doing something wrong or I'm losing my mind.
Here is the image
Here is the XML code
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="#color/background_green"
tools:context="nz.co.listcosolutions.StartActivity">
<ImageView
android:id="#+id/imageView4"
android:layout_width="160dp"
android:layout_height="163dp"
android:layout_marginEnd="95dp"
android:layout_marginStart="95dp"
android:layout_marginTop="32dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/baby_plant" />
<Button
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="64dp"
android:text="#string/next"
android:textColor="#color/background_green"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="20dp"
android:text="Welcome to My App"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView4" />
</android.support.constraint.ConstraintLayout>
Im also using the latest version of ConstraintLayout
compile 'com.android.support.constraint:constraint-layout:1.0.2'
You need to add:
android:gravity="center"
to the TextView.
This is the only certain way to center the text inside a TextView object or one of its subclasses.
The android:textAlignment is not working in all the cases and as reported by this answer that it has problems in lower API levels.