I am getting an error:No enum constant com.android.manifmerger.AttributeOperationType.CONTEXT.
when I am trying to use ConstraintLayout
enter image description here
Here is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="#+id/inputFirstName"
android:layout_width="398dp"
android:layout_height="47dp"
android:layout_margin="10dp"
android:layout_marginEnd="188dp"
android:layout_marginBottom="21dp"
android:hint="Enter your first name"
android:minHeight="48dp"
app:layout_constraintBottom_toTopOf="#+id/inputLastName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.848" />
<EditText
android:id="#+id/inputLastName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="135dp"
android:hint="Enter your last name"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/btnUploadData"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="56dp"
android:layout_marginEnd="8dp"
android:text="#string/save_data"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/inputLastName" />
<Button
android:id="#+id/btnReadData"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="44dp"
android:layout_marginEnd="8dp"
android:text="#string/retrieve_data"
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/btnUploadData"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textViewResultTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="104dp"
android:layout_marginTop="43dp"
android:text="FireStore data :"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/btnReadData" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="8dp"
android:layout_marginTop="48dp"
android:text=""
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textViewResultTitle"
app:layout_constraintVertical_bias="0.081" />
</androidx.constraintlayout.widget.ConstraintLayout>
When I tried to use ConstraintLayout I deleted a and put instead
This is what I found on the forums. It didn't work so I decided to return and put in it "androidx.constraintlayout.widget.ConstraintLayout" but it also gave me an error. So I don't know how to fix it. Maybe it is because of that my xml file is in the manifest folder: enter image description here
Here is my dependencies in build.gradle (:app):
build.gradle (:app) File
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
}
android {
namespace 'com.example.myapplication'
compileSdk 32
defaultConfig {
applicationId "com.example.myapplication"
minSdk 19
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation platform('com.google.firebase:firebase-bom:31.1.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-firestore-ktx:24.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// To use constraintlayout in compose
implementation("androidx.constraintlayout:constraintlayout-compose:1.0.1")
}
According to your screenshot, you've replaced your AndroidManifest.xml's contents with layout XML. That file is extremely important and you'll get all kinds of errors if you try to build without a valid one!
You need to revert it and then create a layout file (in the res/layout folder) for the layout XML you're trying to use
Related
Yesterday everything was ok, but today I've started to working again in my app, in the xml file of an activity but Android Studio show nothing on the phone interface (That one that is located normally to the right, just next to the XML code.) It says that it is a render problem.
Here you can see that the layou is displayed normally but i can't see my edits until I run the app
java.lang.IllegalArgumentException: No drawer view found with gravity RIGHT
at androidx.drawerlayout.widget.DrawerLayout.openDrawer(DrawerLayout.java:1736)
at androidx.drawerlayout.widget.DrawerLayout.openDrawer(DrawerLayout.java:1722)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.android.layoutlib.bridge.util.ReflectionUtils.invoke(ReflectionUtils.java:56)
at com.android.layoutlib.bridge.android.support.DrawerLayoutUtil.openDrawer(DrawerLayoutUtil.java:59)
at com.android.layoutlib.bridge.android.support.DrawerLayoutUtil.openDrawer(DrawerLayoutUtil.java:53)
at android.view.BridgeInflater.postInflateProcess(BridgeInflater.java:577)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.postInflateProcess(RenderSessionImpl.java:702)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.postInflateProcess(RenderSessionImpl.java:707)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:338)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:373)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:713)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$6(RenderTask.java:844)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Note that this errors doesnt show in the logcat, because all is running except the visualizator.
It says something like there is not drawer view with gravity RIGHT, and off course there is not. But IDK why is now searching for it.
Here is my code. I have already worked with this configuration so I think this is not the problem.
<androidx.drawerlayout.widget.DrawerLayout
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/drawer_layout_dar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="end"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/toolbar_dar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/itemBlueDark"
app:title="Sube tu objeto"/>
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:id="#+id/title_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Categoría"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/spinner_Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:inputType="none"
/>
</com.google.android.material.textfield.TextInputLayout>
<Spinner
android:id="#+id/spinner"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/transparent"
android:spinnerMode="dialog"
tools:listitem="#layout/spinner_layout"
/>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/nombre_objeto"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="10dp"
android:layout_marginRight="12dp"
android:background="#color/white"
android:hint="#string/nombre_objeto">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/nombre_objeto_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/desc_objeto"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="10dp"
android:layout_marginRight="12dp"
android:layout_marginBottom="12dp"
android:background="#color/white"
android:hint="#string/descripcion_objeto">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/desc_objeto_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="#+id/img_objeto"
android:layout_width="274dp"
android:layout_height="240dp"
android:layout_gravity="center"
android:layout_marginTop="24dp"
android:src="#drawable/sin_foto" />
<Button
android:id="#+id/btn_enviar_imagen"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:layout_marginBottom="40dp"
android:background="#drawable/forma_btn"
app:backgroundTint="#color/itemBlueDark"
android:text="Subir" />
<Button
android:id="#+id/btn_listaUsuarios"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/cabecera_menu"
app:menu="#menu/menu_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
here you can see that there is a problem w/ the Layout Rendering Engine. I've tried to enable/disable it but it seems it does not work
Here you can see other errors related to the rendering
Althouhg other XML files have the same render issues, AndroidStudio display the desing visualizator properly
EDIT: Here are my dependencies, maybe some of this are wrong, but i doubt it.
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.Trueque"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
//para las cajas de texto
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
//Para dependencias de firebase
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//Para las tabs deslizantes
implementation "androidx.viewpager2:viewpager2:1.0.0"
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:28.2.0')
// Declare the dependency for the Realtime Database library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-database'
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:28.2.0')
// Declare the dependency for the Firebase Authentication library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-storage:20.0.0'
implementation 'com.google.firebase:firebase-auth:21.0.1'
}
I have fixed it by deleting the following lines in the XML file.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/title_spinner"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:hint="Categoría">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/spinner_Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
<Spinner
android:id="#+id/spinner"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/transparent"
android:spinnerMode="dialog"
tools:listitem="#layout/spinner_layout" />
I am experiencing layout issues when trying to use the latest versions of constraint layout. It seems to not follow guideline rules. Is this a bug in the library? My project uses many guidelines and to change every one of them would be a huge pain. Anyone know if there is a work around of am I doing this wrong? This layout issue seems to happen in versions greater than constraint layout 2.0.1.
Constraint layout v 1.1.3
Constraint Layout v 2.0.4 - the location icon is behind my widget constraint layout
MainActivity layout 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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffffff"
android:clickable="true"
android:focusable="true">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/edit_text_message_input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#null"
android:hint="Please Type Something"
android:maxHeight="100dp"
android:minHeight="56dp"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="13dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<requestFocus />
</androidx.appcompat.widget.AppCompatEditText>
<RelativeLayout
android:id="#+id/mic_container"
android:layout_width="140dp"
android:layout_height="140dp"
app:layout_constraintTop_toBottomOf="#+id/edit_text_message_input"
app:layout_constraintBottom_toTopOf="#+id/edit_text_message_input"
app:layout_constraintLeft_toLeftOf="#+id/mic_icon_guideline"
app:layout_constraintRight_toRightOf="#+id/mic_icon_guideline">
<CheckBox
android:layout_centerInParent="true"
android:id="#+id/button_nav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:button="#drawable/navigation_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/mic_icon_guideline"
app:layout_constraintGuide_end="28dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/attachment_icon_container"
android:layout_width="match_parent"
android:layout_height="48dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/edit_text_message_input">
<CheckBox
android:id="#+id/button_add_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:button="#drawable/add_location_button"
app:layout_constraintLeft_toRightOf="#+id/button_remove_location"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="#+id/button_remove_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:button="#drawable/remove_location_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="#+id/button_add_location"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
build.gradle file
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.test_constraint_project"
minSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.core:core-ktx:1.3.2"
implementation "androidx.appcompat:appcompat:1.2.0"
implementation "com.google.android.material:material:1.2.1"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
The RelativeLayout mic_container has the following constraints:
app:layout_constraintTop_toBottomOf="#+id/edit_text_message_input"
app:layout_constraintBottom_toTopOf="#+id/edit_text_message_input"
It doesn't seem right that the top of one view should be constrained to the bottom of another and the bottom of the first view should be constrainted to the top of the second. This is really an invalid situation and I think that you are seeing ConstraintLayout resolving this differently between the two versions.
If you state the following as constraints:
app:layout_constraintTop_toTopOf="#+id/edit_text_message_input"
app:layout_constraintBottom_toBottomOf="#+id/edit_text_message_input"
I think that you will see mic_container positioned appropriately. You will have to determine if this solves all of your problems or not.
I'm trying to use a viewpager in my app which used androidX but it showed me an error ERROR: Failed to resolve: viewpager Affected Modules: app after added implementation 'android.viewpager:viewpager:1.0.0' and Gradle project sync. I searched a lot but not found any solution.please any help thanks in advance.here is xml file.
xml file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Favourites.FavouriteLinks">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread_inside"
app:popupTheme="#style/AppTheme.PopupOverlay"
tools:layout_conversion_absoluteHeight="56dp"
tools:layout_conversion_absoluteWidth="384dp" android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintVertical_bias="0.0">
<TextView
android:id="#+id/toolbar_title"
style="#style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="casual"
android:gravity="left"
android:text="Favourites Brochures"
android:textColor="#color/colorwhite"
android:textSize="18sp"
android:textStyle="bold"
tools:layout_conversion_absoluteHeight="28dp"
tools:layout_conversion_absoluteWidth="56dp"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="14dp"/>
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:tabSelectedTextColor="#android:color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="32dp"
app:layout_constraintTop_toTopOf="#+id/toolbar"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.04000002" android:id="#+id/tabLayout">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="21sp"
android:textStyle="bold"
android:text="tab2"
/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tab1"
android:textSize="21sp"
android:textStyle="bold"
/>
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="508dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.85"/>
</androidx.constraintlayout.widget.ConstraintLayout>
kotlin code
class FavouriteLinks : AppCompatActivity() {
//This is our viewPager
var viewPager: ViewPager? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_favourite_links)
setSupportActionBar(toolbar)
supportActionBar?.setDisplayShowTitleEnabled(false)
viewPager = findViewById<ViewPager>(R.id.viewPager)
val pageAdapter = PageAdapter(supportFragmentManager, tabLayout.tabCount)
viewPager?.adapter = pageAdapter
}
}
gradle file
//noinspection GradleCompatible
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.nanotech.i_cardplatform"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//noinspection GradleCompatible
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
implementation 'com.google.android.material:material:1.0.0-alpha1'
//RETROFIT ... NETWORK LIBRARY
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
// RETROFIT .. CONVERTER
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
// Logging
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
// Room dependencies
implementation 'androidx.room:room-runtime:2.0.0-alpha1'
kapt 'androidx.room:room-compiler:2.0.0-alpha1'
annotationProcessor 'androidx.room:room-compiler:2.0.0-alpha1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'androidx.viewpager:viewpager:1.0.0'
}
repositories {
mavenCentral()
}
Do not add viewPager library separately it's already included in
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
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.
for round about 2 weeks from now, I receive an error message, whenever I try to preview an .xml design-file in my Android Studio Project. As I am relatively new to the whole topic I'd like to ask whether you have an answer.
The error message:
Rendering Problems:
The following classes could not be found:
- android.support.v7.widget.Toolbar
OR
Rendering Problems:
The following classes could not be found:
- android.support.v7.widget.CardView
One of the .xml files:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar_tabs"
android:background="#color/primaryColor"
app:contentInsetStart="0dp"
app:contentInsetEnd="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="VPlan App RC1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textSize="20sp"
android:layout_marginLeft="16dp"
android:fontFamily="sans-serif-medium"
android:id="#+id/textView7"
android:layout_marginStart="16dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_refresh"
android:id="#+id/ic_refresh"/>
</RelativeLayout>
<com.astuetz.PagerSlidingTabStrip
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/primaryColor"
android:textColorPrimary="#color/white"
android:textSize="14sp"
android:id="#+id/tabs"
android:layout_marginTop="?attr/actionBarSize" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
Also as it might help, here's the build.gradle file where the support library is located.
The build.grade file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId 'com.nocomment.vplanehs'
minSdkVersion 10
targetSdkVersion 22
versionCode 16
versionName '0.8.5_RC1'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':volley')
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:cardview-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.jpardogo.materialtabstrip:library:1.0.9'
}
In this project we also use volley as well as libraries from ZXing's QR Code reader.
I'd be very thankful if someone could help me. Thank you in advance!