I could not build my project due to this xml code, but cannot figure out where exactly lays the problem. I first used scrollView, I did delete it, and used ListView instead. Since then could not run my project.
the error I am getting is this:
ParseError at [row,col]:[118,54]
Message: http://www.w3.org/TR/1999/REC-xml-names-19990114#AttributeNSNotUnique?ListView&layout_width&http://schemas.android.com/apk/res/android*
here is the code
<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"
xmlns:anddroid="http://schemas.android.com/apk/res/android"
android:background="#FFFCEC">
<com.google.android.material.tabs.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0BA811"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="48dp"
android:layout_weight="1"
android:orientation="vertical"
android:layoutDirection="rtl"
app:layout_constraintBottom_toBottomOf="#+id/tab_layout" />
<TextView
android:id="#+id/textView2"
android:layout_width="310dp"
android:layout_height="49dp"
android:text="Here where your friends are!"
android:textColor="#127A00"
android:textSize="24sp"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.832" />
<TextView
android:id="#+id/textView4"
android:layout_width="270dp"
android:layout_height="88dp"
android:text="theFinder"
android:textColor="#127A00"
android:textSize="60sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.729" />
<Button
android:id="#+id/btnscan"
android:layout_width="408dp"
android:layout_height="75dp"
android:backgroundTint="#127A00"
android:text="press to Scan"
android:textColor="#EDFFFFFF"
android:textColorHighlight="#FFFFFFFF"
android:textSize="20sp"
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.996" />
<ProgressBar
android:id="#+id/pBar"
style="#android:style/Widget.ProgressBar.Large"
android:layout_width="113dp"
android:layout_height="77dp"
android:indeterminate="true"
android:indeterminateOnly="true"
android:max="100"
android:progress="10"
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.578" />
<TextView
android:id="#+id/tView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#1E7822"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.566" />
<ListView
android:id="#+id/lst_view"
anddroid:layout_width="409dp"
android:layout_width="396dp"
anddroid:layout_height="328dp"
android:layout_height="244dp"
android:background="#D80E1127"
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.141" />```
Your root element specifies two aliases for the same namespace:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:anddroid="http://schemas.android.com/apk/res/android"
Then in the ListView with an ID of #+id/lst_view you specify layout_height and layout_width twice, once with each alias:
anddroid:layout_width="409dp"
android:layout_width="396dp"
anddroid:layout_height="328dp"
android:layout_height="244dp"
That means you're specifying the same namespace-qualified attribute twice for each of width and height. That's not allowed.
Just remove the anddroid typo-alias, and remove the two attributes using it.
Related
I know that there is questions like this on this site but can't apply their solutions on my problem, or simply do not know how. I am trying to make my ConstraintLayout that is part of my layout to be placed on end of my progress,like this:
but in my case it is always on center of progressbar
my xml:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ProgressBar
android:id="#+id/seekBar2"
style="#style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="6dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:progress="60"
android:progressDrawable="#drawable/customprogressbar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/goal_name_TV" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/thumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/tv_content_rounded"
android:paddingStart="8dp"
android:paddingTop="2dp"
android:paddingEnd="8dp"
android:paddingBottom="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/goal_name_TV">
<ImageView
android:id="#+id/bullet_IMG"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingEnd="2dp"
android:src="#drawable/ic_bulet_blue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/marker_value"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/marker_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="985"
android:textColor="#color/background"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/bullet_IMG"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
and my java:
binding.seekBar2.setProgress((int) modelClass.getPercentage());
binding.markerValue.setText(binding.seekBar2.getProgress()+"%");
int position = (((binding.seekBar2.getRight() - binding.seekBar2.getLeft()/binding.seekBar2.getMax()) * binding.seekBar2.getProgress())+ binding.seekBar2.getLeft());
binding.thumb.setTranslationX((float) ((double)position - (binding.thumb.getWidth()/2)));
also i tried to make custom progrssbar but in vain
When adding a constraint layout within another constraint layout the inner one gets cut off.
I already tried changing the constraint top of view but that didn't change anything. Anyone knows why this is happening?
I also tried it out with different layouts ( the cyan one is the culprit ) which all had the same effect.
<?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"
android:background="#color/cyberpunk_background"
tools:context=".Todo_create">
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:autofillHints=""
android:background="#drawable/square_round"
android:ems="10"
android:hint="Title"
android:inputType="textPersonName"
android:textColor="#color/cardview_light_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="148dp"
android:background="#drawable/square_round"
android:ems="10"
android:hint="Description"
android:inputType="textPersonName"
android:textColor="#color/cardview_light_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="104dp"
android:background="#drawable/square_round"
android:clickable="true"
android:ems="10"
android:hint="Time"
android:inputType="textPersonName"
android:textColor="#color/cardview_light_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText3" />
<Button
android:id="#+id/button_add_new_todo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginBottom="32dp"
android:background="#drawable/square_round"
android:text="Button"
android:textColor="#color/cardview_light_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="256dp"
android:adjustViewBounds="true"
android:background="#color/colorAccent"
android:orientation="horizontal"
android:scaleType="centerInside"
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/editText4"
app:layout_constraintVertical_bias="1.0">
<ImageButton
android:id="#+id/imageButton"
android:layout_width="47dp"
android:layout_height="50dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="26dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/alarm_clock_1" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
It seems that you have an unnecessary android:layout_marginBottom="256dp" in your nested constraint layout.
The output of the below code is not coming as the output required . Full Screen is not been covered in the scrollview .I am trying to use Constraint Layout inside the scroll view.Please help.......
The contents of the constraint layout are getting overlaped and the full screen is not covered by constraint layout....
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
xmlns:fancy="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.libizo.CustomEditText
android:id="#+id/Email"
android:layout_width="285dp"
android:layout_height="69dp"
android:ems="10"
android:hint="Email"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.873"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.111"
app:libIZO_clearIconTint="#8f1f15"
app:libIZO_setBorderColor="#8f1f15"
app:libIZO_setBorderView="true"
app:libIZO_setClearIconVisible="true"
app:libIZO_setCornerRadius="4dp"
app:libIZO_setStrokeWidth="2dp" />
<ImageView
android:id="#+id/icon_mail"
android:layout_width="75dp"
android:layout_height="66dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.047"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.115"
app:srcCompat="#drawable/ic_email"
tools:ignore="ContentDescription,UnusedAttribute,VectorDrawableCompat" />
<mehdi.sakout.fancybuttons.FancyButton
android:id="#+id/Login"
android:layout_width="204dp"
android:layout_height="75dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.417"
fancy:fb_borderColor="#FFFFFF"
fancy:fb_borderWidth="1dp"
fancy:fb_defaultColor="#7ab800"
fancy:fb_focusColor="#9bd823"
fancy:fb_iconPosition="left"
fancy:fb_radius="30dp"
fancy:fb_text="Login / Register"
fancy:fb_textColor="#FFFFFF"
fancy:fb_textSize="25dp" />
<ImageView
android:id="#+id/icon_lock"
android:layout_width="80dp"
android:layout_height="68dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.048"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.268"
app:srcCompat="#drawable/ic_lock"
tools:ignore="ContentDescription,UnusedAttribute,VectorDrawableCompat" />
<com.libizo.CustomEditText
android:id="#+id/Password"
android:layout_width="285dp"
android:layout_height="69dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.873"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.268"
app:libIZO_clearIconTint="#8f1f15"
app:libIZO_setBorderColor="#8f1f15"
app:libIZO_setBorderView="true"
app:libIZO_setClearIconVisible="true"
app:libIZO_setCornerRadius="4dp"
app:libIZO_setStrokeWidth="2dp" />
<TextView
android:id="#+id/Forgot_Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot Password ?"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.527" />
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:visibility="gone"/>
<Button
android:id="#+id/Google"
android:layout_width="168dp"
android:layout_height="145dp"
android:background="#drawable/ic_google"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.884"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.725" />
<Button
android:id="#+id/Phone"
android:layout_width="168dp"
android:layout_height="145dp"
android:background="#drawable/ic_phone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.148"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.725" />
<Button
android:id="#+id/Facebook"
android:layout_width="208dp"
android:layout_height="156dp"
android:background="#drawable/ic_facebook"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.541"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.991" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
The Output for the following code is shown here
You set wrong Constraint to view. Try like below. It will give you some idea and change it according your need.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
xmlns:fancy="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/icon_mail"
android:layout_width="75dp"
android:layout_height="66dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_email"
tools:ignore="ContentDescription,UnusedAttribute,VectorDrawableCompat" />
<com.libizo.CustomEditText
android:id="#+id/Email"
android:layout_width="285dp"
android:layout_height="69dp"
android:ems="10"
android:hint="Email"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:libIZO_clearIconTint="#8f1f15"
app:libIZO_setBorderColor="#8f1f15"
app:libIZO_setBorderView="true"
app:libIZO_setClearIconVisible="true"
app:libIZO_setCornerRadius="4dp"
app:libIZO_setStrokeWidth="2dp" />
<ImageView
android:id="#+id/icon_lock"
android:layout_width="80dp"
android:layout_height="68dp"
android:layout_marginTop="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/icon_mail"
app:srcCompat="#drawable/ic_lock"
tools:ignore="ContentDescription,UnusedAttribute,VectorDrawableCompat" />
<com.libizo.CustomEditText
android:id="#+id/Password"
android:layout_width="285dp"
android:layout_height="69dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:textSize="20sp"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Email"
app:libIZO_clearIconTint="#8f1f15"
app:libIZO_setBorderColor="#8f1f15"
app:libIZO_setBorderView="true"
app:libIZO_setClearIconVisible="true"
app:libIZO_setCornerRadius="4dp"
app:libIZO_setStrokeWidth="2dp" />
<mehdi.sakout.fancybuttons.FancyButton
android:id="#+id/Login"
android:layout_width="204dp"
android:layout_height="75dp"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Password"
fancy:fb_borderColor="#FFFFFF"
fancy:fb_borderWidth="1dp"
fancy:fb_defaultColor="#7ab800"
fancy:fb_focusColor="#9bd823"
fancy:fb_iconPosition="left"
fancy:fb_radius="30dp"
fancy:fb_text="Login / Register"
fancy:fb_textColor="#FFFFFF"
fancy:fb_textSize="25dp" />
<TextView
android:id="#+id/Forgot_Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot Password ?"
android:textSize="30dp"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Login" />
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:visibility="gone"/>
<Button
android:id="#+id/Google"
android:layout_width="168dp"
android:layout_height="145dp"
android:layout_marginTop="20dp"
android:background="#drawable/ic_google"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Forgot_Password" />
<Button
android:id="#+id/Phone"
android:layout_width="168dp"
android:layout_height="145dp"
android:background="#drawable/ic_phone"
android:layout_marginTop="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Forgot_Password" />
<Button
android:id="#+id/Facebook"
android:layout_width="208dp"
android:layout_height="156dp"
android:background="#drawable/ic_facebook"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Google"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
I'm trying to convert my relative layout into a Constraint layout to fit every device, but I'm having some problems. On the editor in Android Studio it looks like this:
I made it using a Pixel C as emulator. Now, I tried the app on a Samsung Galaxy tab and this is the result:
Why the buttons are not at center at the screen like in the first picture? This is the code of the xml, as you can see I've even anchored the element to keep the distance between them:
<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:id="#+id/relativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background_main"
android:scaleType="centerCrop"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView2"
android:layout_width="708dp"
android:layout_height="231dp"
android:layout_marginTop="152dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:fontFamily="#font/kotta_one"
android:text="Test del pensiero\n divergente"
android:textColor="#000000"
android:textSize="86dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.57"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.195" />
<Button
android:id="#+id/button_1"
android:layout_width="180dp"
android:layout_height="60dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="76dp"
android:layout_marginBottom="8dp"
android:background="#drawable/button_bg"
android:text="#string/invioA"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/button_2"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="#+id/textView2"
app:layout_constraintTop_toBottomOf="#+id/textView2"
app:layout_constraintVertical_bias="0.028" />
<Button
android:id="#+id/button_2"
android:layout_width="180dp"
android:layout_height="60dp"
android:layout_marginEnd="188dp"
android:layout_marginBottom="8dp"
android:background="#drawable/button_bg"
android:text="#string/invioB"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/textView2"
app:layout_constraintTop_toBottomOf="#+id/textView2"
app:layout_constraintVertical_bias="0.028" />
<Button
android:id="#+id/button_3"
android:layout_width="161dp"
android:layout_height="114dp"
android:layout_marginEnd="8dp"
android:background="#android:color/transparent"
android:fontFamily="#font/kotta_one"
android:text="Area\nDocenti"
android:textAllCaps="false"
android:textColor="#030000"
android:textSize="26dp"
app:layout_constraintEnd_toStartOf="#+id/textView2"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
You are giving wrong width and height to button and textview.
Also, for horizontal button and same width and height you can use chain like below I used.
Here, I give you approx design and also you can use your ConstraintLayout because I have androidx migrated project.
<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/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/add_news_feed_bg"
android:scaleType="centerCrop">
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="Test del pensiero\n divergente"
android:textColor="#000000"
android:textSize="86dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/bg_toolbar"
android:text="invioA"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="#+id/button_2"
app:layout_constraintEnd_toStartOf="#+id/button_2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/button_2" />
<Button
android:id="#+id/button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/bg_toolbar"
android:text="invioB"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/button_1"
app:layout_constraintTop_toBottomOf="#+id/textView2" />
<Button
android:id="#+id/button_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:background="#android:color/transparent"
android:text="Area\nDocenti"
android:textAllCaps="false"
android:textColor="#030000"
android:textSize="26dp"
app:layout_constraintBottom_toTopOf="#+id/textView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here is my 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/nav_and_action_bar_color"
>
<ImageView
android:id="#+id/some_person"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/some_person"
app:layout_constraintBottom_toTopOf="#+id/et_username"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/et_username"
android:layout_width="#dimen/login_page_text_fields_width"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#android:color/white"
android:hint="#string/email_hint"
android:padding="10dp"
app:layout_constraintBottom_toTopOf="#+id/et_password"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/some_person" />
<EditText
android:id="#+id/et_password"
android:layout_width="#dimen/login_page_text_fields_width"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#android:color/white"
android:hint="#string/password_hint"
android:inputType="textPassword"
android:padding="10dp"
app:layout_constraintBottom_toTopOf="#+id/login_button"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/et_username" />
<Button
android:id="#+id/login_button"
android:layout_width="#dimen/login_button_width"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#color/colorAccent"
android:elevation="5dp"
android:onClick="clickedOnLogin"
android:text="#string/login_button"
android:textColor="#android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/et_password" />
</android.support.constraint.ConstraintLayout>
and i seem to be getting this as a result
How do i bring the elements together? I want them to be close together.
You need to define variable for every view, where you want to apply chaining logic. Pick just one:
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintVertical_chainStyle="spread"
app:layout_constraintVertical_chainStyle="spread_inside"
Use below code to get the desired layout.
Changes in the below code of yours is "app:layout_constraintVertical_chainStyle="packed".
<?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/nav_and_action_bar_color">
<ImageView
android:id="#+id/some_person"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/some_person"
app:layout_constraintBottom_toTopOf="#+id/et_username"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<EditText
android:id="#+id/et_username"
android:layout_width="#dimen/login_page_text_fields_width"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#android:color/white"
android:hint="#string/email_hint"
android:padding="10dp"
app:layout_constraintBottom_toTopOf="#+id/et_password"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/some_person" />
<EditText
android:id="#+id/et_password"
android:layout_width="#dimen/login_page_text_fields_width"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#android:color/white"
android:hint="#string/password_hint"
android:inputType="textPassword"
android:padding="10dp"
app:layout_constraintBottom_toTopOf="#+id/login_button"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/et_username" />
<Button
android:id="#+id/login_button"
android:layout_width="#dimen/login_button_width"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#color/colorAccent"
android:elevation="5dp"
android:onClick="clickedOnLogin"
android:text="#string/login_button"
android:textColor="#android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/et_password" />
</android.support.constraint.ConstraintLayout>
I managed to bring the elements close together. According to this page
Chains are controlled by attributes set on the first element of the chain (the "head" of the chain):
So i added this to <ImageView> tag
app:layout_constraintVertical_chainStyle="packed"
and since i did not want it to be at the center vertically i also added this to the same tag
app:layout_constraintVertical_bias="0.4"
So that it is not at the center but is slightly biased towards to the top.