I'm using ConstraintLayout wrapped with layout tags for dataBinding, all layouts works fine in execution and runtime, but I got an annoying issue:
As you see, constraint id's say "Cannot resolve symbol '#+id/tvAccount'", seemed as errors when trying to commit, but there's nothing wrong with workflow or the app, and all works fine as intended. It's same in all xml files. Cleaning, invalidating cache etc. is not fixing it. Has anyone met the same issue ?
Edit:
XML code for splash, it'll say "Cannot resolve symbol '#+id/imageViewSplash'" when you hover on the app:layout_constraintTop_toBottomOf="#+id/imageViewSplash" :
<?xml version="1.0" encoding="utf-8"?>
<layout
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">
<!--suppress AndroidUnknownAttribute -->
<data class="SplashBinding"/>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.splash.SplashFragment">
<ImageView
android:id="#+id/imageViewSplash"
android:layout_width="wrap_content"
android:layout_height="39dp"
android:layout_marginBottom="8dp"
android:contentDescription="#string/content_description_splash_icon"
android:src="#mipmap/splash_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:id="#+id/imageViewSplashLoader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="16dp"
android:contentDescription="#string/content_description_splash_loading"
android:src="#mipmap/splash_loader"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageViewSplash"/>
</android.support.constraint.ConstraintLayout>
</layout>
Edit 2:
It's same error when you hover on app:layout_constraintTop_toBottomOf="#+id/imageViewSplash", even without <layout> tags:
<?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.splash.SplashFragment">
<ImageView
android:id="#+id/imageViewSplash"
android:layout_width="wrap_content"
android:layout_height="39dp"
android:layout_marginBottom="8dp"
android:contentDescription="#string/content_description_splash_icon"
android:src="#mipmap/splash_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:id="#+id/imageViewSplashLoader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="16dp"
android:contentDescription="#string/content_description_splash_loading"
android:src="#mipmap/splash_loader"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageViewSplash"/>
</android.support.constraint.ConstraintLayout>
After keeping layout in the editor i might have got the solution for you. The possible cause here is might be with the xmlns:bind and xmlns:android
Please try following it's not showing me any error.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res/android">
<data></data>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tvAccount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="32dp"
android:text="Account"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tvPhoneValidationTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Phone Validation"
app:layout_constraintEnd_toEndOf="#id/tvAccount"
app:layout_constraintStart_toStartOf="#id/tvAccount"
app:layout_constraintTop_toBottomOf="#id/tvAccount" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
I've resolved the same issue by moving the app namespace from <layout/> to <ConstraintLayout/> tag.
Before:
<layout 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">
<androidx.constraintlayout.widget.ConstraintLayout
...>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
After:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
...>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Related
I am fairly new with Android Studio and have ran into a problem that I have not come across before. Within an xml layout I am having a ParseError on line 22, which is the layout_height for the ScrollView. The error says Resource Compilation Failed. I have checked any posts that are even remotely close to this issue and have had no luck so far. Any tips would be appreciated.
<?xml version="1.0" encoding="utf-8"?>
<layout android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SizeFragment"
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">
<data>
<variable
name="orderModel"
type="com.example.pizzaorder.model.OrderModel" />
<variable
name="sizeFragment"
type="com.example.pizzaorder.SizeFragment" />
</data>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textview.MaterialTextView
android:id="#+id/welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:gravity="center"
android:text="#string/welcome"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/twelve_inch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="72dp"
android:layout_marginEnd="32dp"
android:onClick="#{() -> sizeFragment.moveToBase(12)}"
android:text="#string/size_twelve"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/welcome" />
<Button
android:id="#+id/eighteen_inch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:onClick="#{() -> sizeFragment.moveToBase(18)}"
android:text="#string/size_eighteen"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/twelve_inch" />
<Button
android:id="#+id/twenty_four_inch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:onClick="#{() -> sizeFragment.moveToBase(24)}"
android:text="#string/size_twenty_four"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/eighteen_inch" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</layout>
As per the comment, remove height, width, and context from the layout tag and put it in the ScrollView tag. The layout tag does not support these attributes, it is only used to create the data binding and to hold the variables.
I made xml file for my bottom sheet, everything works nice it shows texts but it is not showing images although in my preview I have imageViews, however when I run the app the images disappear.
Here is part of my xml code of Bottom Sheet:
<?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:id="#+id/trip_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<TextView
android:id="#+id/carModel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginTop="22dp"
android:fontFamily="#font/roboto_medium"
android:text="#string/white_cobalt_textView"
android:textColor="#2C2C2C"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/licensePlate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="55dp"
android:fontFamily="#font/roboto_medium"
android:lineSpacingMultiplier="1.20"
android:text="01 | A 717 CB"
android:textColor="#2C2C2C"
android:textSize="20sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/callingBtn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="18dp"
android:contentDescription="#string/call_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/bnt_call" />
</androidx.constraintlayout.widget.ConstraintLayout>
I am using BottomSheet in google maps activity, here is xml code where bottom sheet is attached:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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=".MapsActivity">
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include layout="#layout/bottom_sheet_trip_details" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
You need to use AppCompatImageView to use srcCompat.
Try this:
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/callingBtn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="18dp"
android:contentDescription="#string/call_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/bnt_call" />
I set image with android:background="#drawable/" property and it worked!
But I don't know why it was not showing image with property: app:srcCompat="#drawable/" or app:src=""
First of all I have deep search for that and I didn't find any related topic or solution :(
I have created a library project and import it as a library in another project, this library in all of its views use Android dataBinding, I need to override a xml view or portion of it(say include) in my project
as follow :
product_details_quantity_layout.xml in Library
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_quantity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dim_product_details_sc_quantity_view_mrgn_top"
android:layout_marginBottom="#dimen/dim_product_details_sc_quantity_view_mrgn_bottom"
android:background="#drawable/product_quantity_bg"
android:gravity="center"
android:layoutDirection="ltr"
android:paddingStart="#dimen/dim_product_details_sc_quantity_view_padding_start"
android:paddingTop="#dimen/dim_product_details_sc_quantity_view_padding_top"
android:paddingEnd="#dimen/dim_product_details_sc_quantity_view_padding_start"
android:paddingBottom="#dimen/dim_product_details_sc_quantity_view_padding_bottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.42">
<ImageView
android:id="#+id/iv_decrement"
multipleClick="#{true}"
android:layout_width="0dp"
android:layout_height="0dp"
android:onClick="#{decreaseBtnClick}"
android:src="#drawable/ic_minus"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1.4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.15" />
<ImageView
android:id="#+id/iv_increment"
multipleClick="#{true}"
android:layout_width="0dp"
android:layout_height="0dp"
android:onClick="#{increaseBtnClick}"
android:src="#drawable/ic_add"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1.4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.15" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#{productQty}"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/iv_increment"
app:layout_constraintStart_toEndOf="#id/iv_decrement"
app:layout_constraintTop_toTopOf="parent"
tools:text="1" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<data>
<import type="android.view.View" />
<variable
name="productQty"
type="String" />
<variable
name="increaseBtnClick"
type="android.view.View.OnClickListener" />
<variable
name="decreaseBtnClick"
type="android.view.View.OnClickListener" />
</data>
</layout>
And in my project
product_details_quantity_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<layout 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"
tools:context=".ui.view.product_details.ProductDetailsActivity"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_quantity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layoutDirection="ltr"
android:paddingStart="#dimen/dim_product_details_sc_quantity_view_padding_start"
android:paddingTop="#dimen/dim_product_details_sc_quantity_view_padding_top"
android:paddingEnd="#dimen/dim_product_details_sc_quantity_view_padding_start"
android:paddingBottom="#dimen/dim_product_details_sc_quantity_view_padding_bottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.42">
<ImageView
android:id="#+id/iv_decrement"
multipleClick="#{true}"
android:layout_width="0dp"
android:layout_height="0dp"
android:onClick="#{decreaseBtnClick}"
android:src="#drawable/ic_minuse_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.23" />
<ImageView
android:id="#+id/iv_increment"
multipleClick="#{true}"
android:layout_width="0dp"
android:layout_height="0dp"
android:onClick="#{increaseBtnClick}"
android:src="#drawable/ic_add_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.23" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#{productQty}"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/iv_increment"
app:layout_constraintStart_toEndOf="#id/iv_decrement"
app:layout_constraintTop_toTopOf="parent"
tools:text="1" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<data >
<import type="android.view.View" />
<variable
name="productQty"
type="String" />
<variable
name="increaseBtnClick"
type="android.view.View.OnClickListener" />
<variable
name="decreaseBtnClick"
type="android.view.View.OnClickListener" />
</data>
</layout>
In this I got exception class cast exception, it can't cast the generated databinding class from child to the dataBinding in Parent
so I updated the tag in my project xml file to
after that it work fine and inflate the new view, but when generating new APK it give duplicated class error that the found twice in parent and child projects
so dears any help in this case will be highly appreciated.
Update
This my Include tag in the full xml file in parent
<include
android:id="#+id/cl_quantity"
layout="#layout/product_details_quantity_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:decreaseBtnClick="#{()->viewModel.onDecreaseQty()}"
app:increaseBtnClick="#{()->viewModel.onIncreaseQty()}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:productQty="#{String.valueOf(viewModel.productQty)}" />
Second Update Adding Import
<?xml version="1.0" encoding="utf-8"?>
<layout 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"
tools:context=".ui.view.product_details.ProductDetailsActivity"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_quantity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layoutDirection="ltr"
android:paddingStart="#dimen/dim_product_details_sc_quantity_view_padding_start"
android:paddingTop="#dimen/dim_product_details_sc_quantity_view_padding_top"
android:paddingEnd="#dimen/dim_product_details_sc_quantity_view_padding_start"
android:paddingBottom="#dimen/dim_product_details_sc_quantity_view_padding_bottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.42">
<ImageView
android:id="#+id/iv_decrement"
multipleClick="#{true}"
android:layout_width="0dp"
android:layout_height="0dp"
android:onClick="#{decreaseBtnClick}"
android:src="#drawable/ic_minuse_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.23" />
<ImageView
android:id="#+id/iv_increment"
multipleClick="#{true}"
android:layout_width="0dp"
android:layout_height="0dp"
android:onClick="#{increaseBtnClick}"
android:src="#drawable/ic_add_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.23" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#{productQty}"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/iv_increment"
app:layout_constraintStart_toEndOf="#id/iv_decrement"
app:layout_constraintTop_toTopOf="parent"
tools:text="1" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<data >
<import type="***.databinding.ProductDetailsQuantityLayoutBinding"/>
<import type="android.view.View" />
<variable
name="productQty"
type="String" />
<variable
name="increaseBtnClick"
type="android.view.View.OnClickListener" />
<variable
name="decreaseBtnClick"
type="android.view.View.OnClickListener" />
</data>
</layout>
Using the include tag, you can pass variables.
<include android:id="#+id/secondary"
layout="#layout/data_binding_included_secondary_layout"
bind:secondaryUser="#{mainUser}"/>
Ref:
https://medium.com/#elia.maracani/android-data-binding-passing-a-variable-to-an-include-d-layout-3567099b58f
So if you have an include tag in your Library module, then override that xml file in your resources, you may be able to change it.
Ref:
Override resources in library android
Alternatively, you can programmattically add a view into your XML, it should work if you use the correct viewbing tags:
Ref:
Programmatically adding a layout + children
You can use class attribute to avoid cast exception.
https://developer.android.com/topic/libraries/data-binding/generated-binding#custom_binding_class_names
However, It seems the binding class is still from library project class.
So, we can't override binding behavior. we can't add|remove binding elements from base library project xml.
we can customize element only that area unrelated to data binding.
I'm new to Android development. I created an activity/layout with two views. The first one is a custom button that I want to be 50dp high. The second is a list view that I want to take the rest of the screen below it.
My problem is that when I constrain them to each other, the ListView gets crushed to 0 and the "springs" around the 50dp button expand to take all the space. Here I've given the list a height of 200dp so you can see it. If I set it to "match constraint" it goes to 0. There is content in the list.
With iOS constraints I know how to do this. The constraints around the button are behaving like "greater than or equal" constraints in iOS. I want them to be "equal". How do you do this in Android?
Here's the XML.
<?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"
app:layout_constrainedHeight="false"
tools:context=".WorkoutActivity">
<mycompany.PlayPauseButton
android:id="#+id/play_pause_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/workout_list"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="#+id/workout_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
You have to attach the top of listView to the bottom of playButton not other way around
<?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"
app:layout_constrainedHeight="false"
tools:context=".WorkoutActivity">
<mycompany.PlayPauseButton
android:id="#+id/play_pause_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="#+id/workout_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="8dp"
app:layout_constraintTop_toBottomOf="#id/play_pause_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Cheers :)
Since you want the ListView to occupy all of the available space, it is a good idea to set the height to 0dp. This is sorta like a stretch-me-how-you-like scheme for ConstraintLayouts. The height would therefore entirely depend on the top and bottom constraints. So, nice step!
Your mistake, however, was the way you constrained your views. You were supposed to constrain the ListView to the bottom of play_pause_button (as shown below). This way, the position of the ListView is always dependent on (and below) playButton.
<?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"
app:layout_constrainedHeight="false"
tools:context=".WorkoutActivity">
<mycompany.PlayPauseButton
android:id="#+id/play_pause_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="#+id/workout_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="8dp"
app:layout_constraintTop_toBottomOf="#id/play_pause_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I hope this helps. Merry coding!
Just set the constraints the right way. No constraint bottom in the button but a constraintTop in the listview.
<?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"
app:layout_constrainedHeight="false"
tools:context=".ui.MainActivity">
<mycompany.PlayPauseButton
android:id="#+id/play_pause_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="#+id/workout_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/play_pause_button"/>
</androidx.constraintlayout.widget.ConstraintLayout>
this is working for me :
<?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"
app:layout_constrainedHeight="false">
<mycompany.PlayPauseButton
android:id="#+id/play_pause_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ListView
android:id="#+id/workout_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/play_pause_button"/>
</androidx.constraintlayout.widget.ConstraintLayout>
With constraint layout, it's usually (at least in my experience) a lot easier to build either top-down or bottom-up, so get one component into a position where you're happy with it and then add then next one, maybe that helps
All error occurs at same time I'm using latest version 3.0 but this error can't be solved I tried many ways
style ->theme
invalid cache
Change API but all does not work kindly need for your help..
drag button in UI but button not show on UI and above error occur .
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="com.example.yousa.myapplication3.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button"
tools:layout_editor_absoluteX="69dp"
tools:layout_editor_absoluteY="102dp" />
</android.support.constraint.ConstraintLayout>