NotSibling: Invalid Constraints - java

While executing my project I came across a problem and I'm not sure what causes it. The error I'm getting is
"....../file.xml" 41: #+id/secureText is not a sibling in the same ConstraintLayout
The complete file code is
<?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=".ui.activities.SpeedTestActivity"
android:background="#drawable/background_main">
<com.github.anastr.speedviewlib.PointerSpeedometer
android:id="#+id/speedView"
android:layout_width="240dp"
android:layout_height="240dp"
android:layout_marginStart="8dp"
android:layout_marginTop="36dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:speedTextSize="0sp" />
<TextView
android:id="#+id/speedText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:text="0.00MB/S"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/speedView" />
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adVBannerSpeedTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/secureText" // <- the problematic line
android:layout_centerHorizontal="true"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="44dp"
ads:adSize="BANNER"
ads:adUnitId="#string/admob_banner_id1"
ads:layout_constraintBottom_toTopOf="#+id/startTest"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/startTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="40dp"
android:textColor="#android:color/white"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:background="#drawable/connect_button_background"
android:text="Start Speed Test"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>

ConstraintLayout can only handle the alignment among its children.
<ConstraintLayout>
<This>
<Are>
<All>
<Children>
</ConstraintLayout>
However when you say to ConstraintLayout something like
<ConstraintLayout>
<Childrens
android:layout_below="#id/secureText">
</ConstraintLayout>
<TextView
android:id="#+id/secureText"/>
ConstraintLayout will fail to understand you and will not imply that constrain and will give you a warning.

You can align only children of the parent ConstraintLayout.
You haven't got any view with id secureText in your ConstraintLayout. Probably you want to set it to speedText instead.

in my case, I resolved it by updating the Kotlin version.

Related

Fragment Layout

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.

How come you're not suppose to use match_parent in constraint layout?

Everything I've read online says to not use match_parent in the Constraint View for the height and width properties because it can't be used and won't work. I have used a constraint layout in a few projects now where I do use match_parent and it does work. Was there an update that I haven't noticed to where it is now able to be used? If not, how come it is working in my situations while it seems it doesn't work at all for other people?
Example 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="wrap_content"
android:background="#f9d1ff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/preview"
android:layout_marginLeft="4dp"
android:text="Last Entry:"
android:textSize="12dp"
app:layout_constraintTop_toTopOf="#id/saveButton"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="#id/clearButton"
android:id="#+id/dataText"
android:textSize="16dp"
android:layout_marginLeft="8dp"
android:text=""
android:textStyle="bold"
/>
<Button
android:layout_width="75dp"
android:layout_height="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#+id/clearButton"
android:id="#+id/saveButton"
android:text="Save"
android:textSize="12dp"
android:layout_margin="8dp"
android:background="#drawable/buttonscreen"
android:padding="6dp"/>
<Button
android:layout_width="75dp"
android:layout_height="30dp"
android:gravity="center"
android:padding="6dp"
android:layout_gravity="center_horizontal"
android:layout_margin="8dp"
android:text="Clear All"
android:id="#+id/clearButton"
android:textSize="12dp"
app:layout_constraintTop_toBottomOf="#+id/saveButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/saveButton"
app:layout_constraintEnd_toEndOf="#id/saveButton"
android:background="#drawable/buttonscreen"/>
</androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Try this constraints for which view you want to make match parent

Suggestion Strip of Soft Keyboard hides part of the layout

I've tried virtually every solution out there for soft keyboard covering part of the view when pops up, on further investigation I found that it's not the keyboard but the suggestions strip that's covering the layout.
But disabling the suggestion strip from the settings of the keyboard seems the only solution.
I've tried some hacks which add padding at runtime when the keyboard pops up but none seems to work.
This screenshot will explain it better
The below code snippet is from my BottomSheetDialog:
<?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"
android:id="#+id/design_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/feedback_text"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="#drawable/recognition_text_box_border_drawable"
android:gravity="start"
android:hint="#string/manager_recognition_edit_text_hint"
android:importantForAutofill="no"
android:inputType="textMultiLine|textCapSentences"
android:maxLength="200"
android:maxLines="24"
android:overScrollMode="always"
android:padding="8dp"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:textColor="#android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/award_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="#id/feedback_text"
app:layout_constraintEnd_toEndOf="#id/feedback_text"
app:srcCompat="#drawable/trophy_golden" />
<include
android:id="#+id/award_badge_item"
layout="#layout/award_badge_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="#id/feedback_text"
app:layout_constraintStart_toStartOf="#id/feedback_text" />
<LinearLayout
android:id="#+id/buttons_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:orientation="horizontal"
android:weightSum="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/feedback_text">
<Button
android:id="#+id/cancel_recognition"
style="#style/Widget.AppCompat.Button"
android:layout_width="0dp"
android:layout_height="#dimen/medium_button_height"
android:layout_margin="4dp"
android:layout_weight="1"
android:text="#android:string/cancel" />
<Button
android:id="#+id/send_recognition"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="0dp"
android:layout_height="#dimen/medium_button_height"
android:layout_margin="4dp"
android:layout_weight="2"
android:text="#string/send_recognition" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
add this line in your manifest activity tag where you are opening keyboard
android:windowSoftInputMode="stateHidden|adjustResize"

TextView Not centered in app but centered in match_constraint

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.

Remove white border around fragment

I have a problem when i try to display a listview in my fragment, it seems like there is a white border around the fragment. I also have a similar listview displayed in an activity and it matches perfectly with the borders of the screen.
I'm gonna post below the xml file and a screenshot I took of the fragment, I hope you can help me out.
<?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">
<!-- displays the loading animation while downloading the listview -->
<RelativeLayout
android:id="#+id/loadingPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
</RelativeLayout>
<TextView
android:id="#+id/tv_benvenuto"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Ecco l'elenco completo dei libri a catalogo."
android:textColor="#android:color/black"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView2" />
<ListView
android:id="#+id/lv_dashboard"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tv_benvenuto" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Benvenuto"
android:textColor="#android:color/black"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:includeFontPadding="false"
android:text="#string/empty_dashboard"
android:textAlignment="center"
android:textSize="18sp"
android:visibility="gone"/>
</android.support.constraint.ConstraintLayout>
Image of my fragment problem
Your Listview is inheriting the Benvenuto Textview's margins as it's set to aling it. Put the views in a LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Benvenuto"
android:textColor="#android:color/black"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_benvenuto"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Ecco l'elenco completo dei libri a catalogo."
android:textColor="#android:color/black"
android:textSize="18sp" />
<ListView
android:id="#+id/lv_dashboard"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Sometimes when you set the width and height to match-constraint I've noticed that it adds some imaginary padding like this for whatever reason. It looks like this layout is pretty simple and just linearly goes from top to bottom in terms of its views. Why don't you just use a LinearLayout instead, and set the dimensions to matchparent? That should fix it, unless you need to add more stuff to this layout.

Categories