Coding a constraint layout:
<View
android:id="#+id/divider"
style="#style/divider_style"
android:layout_width="0dp"
swedbank:layout_constraintBottom_toBottomOf="parent"
swedbank:layout_constraintLeft_toLeftOf="parent" />
<ImageView
android:id="#+id/some_image"
style="#style/some_style"
swedbank:layout_constraintBottom_toBottomOf="#+id/divider" <!-- This '+' -->
swedbank:layout_constraintRight_toRightOf="parent"
swedbank:layout_constraintTop_toTopOf="#+id/divider" /> <!-- This '+' -->
See the comments: the plusses on those lines must be there for the android studio layout renderer to work. without them you get:
Couldn't resolve resource #id/divider Tip: Try to refresh the layout.
I always thought #+id/ was for the first time you defined an id?
I've experienced IDE problems if I use +'es everywhere some years ago: With goto-definition the IDE would not know which id to go to
Tested on Android studio 2.3.3 and 3.0.1
Seeing as the auto-complete gives you plusses everywhere should i just go with that?
Try adding this to your dependencies section in the gradle
compile 'com.android.support.constraint:constraint-layout:1.0.2'
Related
After updating to ConstraintLayout 2.0 I realized that even the simplest layouts can not be previewed properly in Android Studio, both on OS X and Ubuntu.
First, my setup looks like this: I'm using "androidx.constraintlayout:constraintlayout:2.0.0", the version of Android Studio is 4.0.1 (the latest stable release) on both of my computers, the version of Android Gradle plugin is 4.0.1, the version of Gradle is 6.1.1.
Here's an example:
<?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">
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I would expect it to draw the TextView aligned to the top of the screen.
What I end up seeing instead is this:
I tried turning off the experimental rendering engine as AS warned me there might be some issues with it but to no avail.
Is there something obvious I might be missing? Since 2.0.0 was in release for 2-3 days (and the release candidate was available for a wide audience for longer than that), I assume all obvious glitches should've been resolved at this point.
Upd. AS states there is a following rendering problem:
java.lang.NoClassDefFoundError: Could not initialize class androidx.constraintlayout.widget.ConstraintLayout$LayoutParams$Table
at androidx.constraintlayout.widget.ConstraintLayout$LayoutParams.<init>(ConstraintLayout.java:2603)
at androidx.constraintlayout.widget.ConstraintLayout.generateLayoutParams(ConstraintLayout.java:1823)
at androidx.constraintlayout.widget.ConstraintLayout.generateLayoutParams(ConstraintLayout.java:481)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1125)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1097)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:501)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:348)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:404)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:678)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$8(RenderTask.java:809)
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)
Upd. 2 I've submitted a bug report, let's see if this is a bug with Android Studio / Constraint Layout indeed (which I think is not the case).
Ok, in my case this definitely looks like an issue with a project cache. Once I've cleaned it up (Build -> Clean Project), the layout preview started working just fine.
I am having the same issue after updating to 2.0.0, I believe this is an AS/Constraint Layout issue. Using version 1.1.3, for the time being, works just fine.
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
I'm trying to use the Barrier view in ConstraintLayout:
<android.support.constraint.Barrier
android:id="#+id/buttonBarrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="top"
app:constraint_referenced_ids="answer1Button,answer2Button"
/>
It works fine in the IDE, and I get Barrier-specific lint messages. But when I run the app, it crashes trying to inflate the layout containing the Barrier:
java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.Barrier"
I am using AndroidX ConstraintLayout 1.1.3:
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
What's happening here?
The xml tag is androidx.constraintlayout.widget.Barrier in the latest AndroidX version.
I have got a strange situation when I working on my project.I have just run my application once. Then I changed some "android:margin" properties for my XML files. Then the problem came. I ran the project and it crashed. The log says it comes Resource Not Found Exception. Next I tried to export it but it failed to export. I'll post the log and error dialog below.
What have I done:
I reinstalled everything such as eclipse,ADT and SDK. Not work at all. I'm absolutely sure that the resource exists and stays in right position.**
All useful information is needed.
ps: The resource file that not found is an activity layout xml file--my intro activity and I've found the resource id in my R file.
ps: My friends use the same code as me.They don't have any problem.
here's my layout xml file:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fl_base_activity"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/iv_base_wallpaper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#color/trans_cc" />
</FrameLayout>
Try re-building your project , If that doesn't work , delete the 'build' and 'gen' folders of project(you can take a backup elsewhere but remove them from your project folder) and then try running it again.
Let me know if that works.....
I've found why : So stupid fail that there is a resource with no suffix has been add in my project from SVN. It has a same name with correct resource name but without .png, eclipse can't distinguish what's the difference between them. It has no error notice. WTF!
Recently I’ve upgraded from Android Studio 1 to Android Studio Beta 1.2.
And among other issues, it seems that the shortcut (Option + Command + L) for formatting the xml-layouts it doesn’t reorganice code any more.
In the previous version of Android Studio, if you had something like this:
<RelativeLayout
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/_10dp"
android:id="#+id/rl_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
After formatting you got the next result:
<RelativeLayout
android:id="#+id/rl_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/_10dp">
But now I just get this message: “No lines changed. Code is already properly formatted”
Is there any kind of configuration that I’m missing it?
Thanks!
Try Ctrl+Shift+Alt+L, you should have a dialog where you can tick "Rearrange".
The Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:weightSum="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="#+id/edit_message"
android:layout_weight = "1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:id="#+id/bSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
The error message:
BUILD FAILED
C:\My First App\res\layout\activity_main.xml:7: Unexpected element "{}LinearLayout" {antlib:org.apache.tools.ant}LinearLayout
The code is almost exactly the same as the code on the Android website and it's really frustrating that I can't seem to get it to work. Is the problem in the code, or is it on my side? I am using Eclipse
I was getting the same error. I was using Indigo in Ubuntu 12.04, and no matter what libraries I got or eclipse plugins I used it was always there.
What worked for me was re-downloading and reinstalling the Android SDK (probably not necessary in your case), and downloading Eclipse Classic (Juno) from the Eclipse website rather than using the Indigo package that was in the repos. The lesson said Classic was recommended anyway, so whatever, I'm just happy it works now.
If you are using Windows, I'd still suggest downloading the most recent Classic version, but otherwise I can't be of help there.