I'm just trying to use the group view with the android constraint layout to set the visibility of several views more easily. Problem is even though I change the visibility of a group to gone or invisible it does not do anything.
I'v already tried the steps of Pavan's response in this thread: toggle visibility of chain group in constraint layout.
But it didn't change anything for me. (I assume it's because I'm not using the beta version)
Here is my dependencies app gradle file
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
This is an extract of my XML file with the group
<Button
android:text="#string/action_update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button_update"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp" app:layout_constraintStart_toStartOf="parent" android:textSize="18sp"/>
<android.support.constraint.Group android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/group"
android:visibility="gone"
app:constraint_referenced_ids="button_update"/>
You are importing the Group widget from a wrong package.
Change
<android.support.constraint.Group
To
<androidx.constraintlayout.widget.Group
Updated Version
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
..............................................
>
<Button
android:id="#+id/button_update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="32dp"
android:text="#string/action_update"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="#+id/group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:constraint_referenced_ids="button_update" />
</androidx.constraintlayout.widget.ConstraintLayout>
The thing is I didn't notice that when I created my android studio project, i didn't check the box "Use androidx artifacts" which automatically makes your project use the new androidx library. Androidx tends to replace the support library (See more details here: https://developer.android.com/jetpack/androidx)
So basically, I followed the steps given here to convert my project to androidx and now everything is working perfectly.
Thank for your time #theapache64, now your code is working.
Related
I'm facing error in using this view
Code is as following:
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/circleImageView"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
i tried checking dependencies, it didn't work
What is the error?
I simply add
implementation 'de.hdodenhof:circleimageview:3.1.0'
to the apps build.gradle dependencies and copied your code in the xml and it worked.
This question already has answers here:
How to add cardview in layout xml in AndroidX
(10 answers)
Closed 3 years ago.
I am following this tutorial for Android app :
https://www.youtube.com/watch?v=wW-AAXOy4u4
I added a list that may contain some items; For each item, I want it to be a Card. Created the card, imported dependencies in build.gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.squareup:android-times-square:1.6.5#aar'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.android.material:material:1.2.0-alpha01'
implementation 'androidx.cardview:cardview:1.0.0'
}
as suggested here:
android.support.v7.widget.CardView could not be found (Android Studio 1.1 Preview)
Nevertheless, I still get the "android.support.v7.widget.CardView could not be found" error.
The error that I get:
The following classes could not be found:
- android.support.v7.widget.CardView (Fix Build Path, Edit XML, Create
Class)
Tip: Try to build the project. Tip: Try to refresh the layout.
Here is my main_activity_single_item code:
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/colorAccent"
android:elevation="4dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="80dp"
android:layout_height="105dp"
android:id="#+id/ivMain"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvMain"
android:textStyle="bold"
android:layout_toRightOf="#+id/ivMain"
android:layout_marginLeft="6dp"
android:layout_toEndOf="#+id/ivMain"
android:text="Timetable"
android:textSize="24sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvDescription"
android:layout_below="#+id/tvMain"
android:layout_toRightOf="#+id/ivMain"
android:layout_marginLeft="6dp"
android:text="Description"
android:textSize="16dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvClick"
android:textSize="12dp"
android:text="click here"
android:layout_below="#+id/tvDescription"
android:layout_alignBottom="#+id/ivMain"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
What I already tried:
changed in
res->value->styles
from <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
to <style name="AppTheme" parent="Base.Theme.AppCompat.Light.NoActionBar">
(error)
File .. Invalidate caches / restart
Build project
I work on Android Studio, my API version is 22
Can you please, share your insights on this issue ?
Please let me know if you need some extra information.
Thank you very much.
Either use
androidx.cardview.widget.CardView
or
com.google.android.material.card.MaterialCardView
instead of
android.support.v7.widget.CardView
The label hint color doesnt works, i created the color Bluesky, but only works with the linear box but the label dont.
<android.support.design.widget.TextInputLayout
android:id="#+id/til1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="14dp"
android:layout_marginEnd="0dp"
android:layout_weight=".8"
android:textColorHint="#color/BlueSky"
app:boxStrokeColor="#color/BlueSky"
app:counterEnabled="true"
app:counterMaxLength="7"
app:errorEnabled="true"
app:hintEnabled="true">
<android.support.design.widget.TextInputEditText
android:id="#+id/tid1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="9dp"
android:elevation="7dp"
android:hint="Test"
android:inputType="number|numberDecimal"
android:maxLength="7"
android:textSize="18sp" />
</android.support.design.widget.TextInputLayout>
mi build gradle:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-
layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation'com.android.support.test.espresso:espresso-core:3.0.2'
}
I use the version 3.4 of android studio.
the label color on the input layout is the colorAccent of your project. If you change this color to BlueSky you'll see what you want.
<color name="colorAccent">#D81B60</color>
But maybe there's another way to style this widget without changing the colorAccent (because this color is used by other widgets too).
Have added a Google Sign in and Facebook button as shown below
<com.google.android.gms.common.SignInButton
android:id="#+id/loginWithGPlusBtn"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.1"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toTopOf="#+id/loginWithFacebookBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/raylImage"
app:srcCompat="#mipmap/ic_gp_login" />
<com.facebook.login.widget.LoginButton
android:id="#+id/loginWithFacebookBtn"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintStart_toStartOf="parent" />
Now, although the G+ button shows up properly, with the text in the middle of the box, I have no such luck with FB. I can manually add a fixed padding like this:
android:paddingTop="10dp"
but this will take away the flexibility of positioning for different sized screens. Tried different settings, but no luck yet. Any ideas ?
Gradle dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:percent:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.facebook.android:facebook-core:[4,5)'
implementation 'com.facebook.android:facebook-login:[4,5)'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
my sample xml file to introduce my problem is this:
<?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">
<TextView
android:id="#+id/toBeUpdated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layoutDirection="rtl"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="#string/update_text_view"
android:onClick="updateTextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="274dp" />
</android.support.constraint.ConstraintLayout>
I want my (toBeUpdated) textView to have "rtl" layoutDirection. With this code we have above every thing is ok until the time textView must be updated. After (for any reason) I update this textView at run time the view jump to the left of the Guideline. I found what's wrong. The reason behind this sudden jump is that when direction is right to left so right is the start and left is the end of view (as you know completely reverse of usual). So my new and corrected version of this xml file to solve this issue is
new version of 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">
<TextView
android:id="#+id/toBeUpdated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layoutDirection="rtl"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="#string/update_text_view"
android:onClick="updateTextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="274dp" />
</android.support.constraint.ConstraintLayout>
in this version, at first, textView is in wrong place but after it is updated, it jump where I want. Completely reverse of first situation where the textView was in correct place until It was not updated and after that, jump happens.
In both cases a sudden unwanted jump happen. It may overlaps some other view or be overlapped by them.
And the most important thing is that maybe I don't want it to be updated even one time and that is an static title. What shall I do?
Is this a Bug or something?
build.gradle (Module: app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "example.com.testconstraintlayout"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
I can't think of any reason why the text view should jump when the contents are updated. I think that this is a bug and that it is probably related to left/right and start/end confusion that crops up now and again.
You don't show screen shots and I can't be sure of what you are trying to achieve, but I think a work-around for you is to use left/right instead of start/end for the text view as follows:
<TextView
android:id="#+id/toBeUpdated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layoutDirection="rtl"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="#+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
I have tried this out and the view does not jump as it does with start/end.