I have a module called TestGUILib and I have specified testview.xml with a simple FrameLayout.
<FrameLayout 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="match_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Testing View!" />
</FrameLayout>
I tried to use this layout in my main app activity_main. Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.sam.testapp1.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" />
<include layout="#layout/testview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
</android.support.constraint.ConstraintLayout>
Everything works fine. It compiles ok and runs ok. But the preview doesn't work. It shows the blank screen (ie. when I clicked on "Design", it turns blank) with render errors:
Could not find layout resource matching value 0x7F04002F (resolved name: testview) in current configuration.
Also, there is a line under testview (ie. include layout="#layout/testview"). When I rolled my mouse over, it said
Typo in the word 'testview'
Spellchecker inspection helps locate typos and misspelling in your code, comments and literals, and fix them in one click.
Any idea? Thanks
go to "File > Invalidate Caches/Restart...", click "Invalidate and Restart". it should work.
Lets assume you have moduleOne and moduleTwo and if you want to use moduleTwo resources in moduleOne add following (sample) code in moduleOne gradle
dependencies {
compile project(':moduleTwo')
}
This will include moduleOne into you moduleTwo in order to use its resouces including layouts.
Possible you have forgotten to enable
buildFeatures {
viewBinding true
}
in the second module. In that case viewbinding will not find view and show it red like an unknown element
Related
When I put "app:" in main_activity.xml, doesn't work the autocompletion, it only shows 1 option:
appNs
But when I do in another xml like fragment_owl.xml, it gives me all the attributes of app namespace.
I have xmlns:app="http://schemas.android.com/apk/res-auto in both of them
this are my xmls
activity_main.xml: (that has autocompletion of app namespace attributes)
<?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">
<TextView
android:id="#+id/holamundo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="69dp"
android:text="Hola Mundo"
android:textAllCaps="false"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/roll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="134dp"
android:text="GIRAR"
android:textSize="36sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="#+id/dice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/empty_dice"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat = "#drawable/dice_1"
/>
<!-- android:src="#drawable/dice_1"-->
</androidx.constraintlayout.widget.ConstraintLayout>
but in this another one:
<?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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<fragment
android:id="#+id/navHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:navGraph="#navigation/navigation"
app:defaultNavHost="true"
app <- NO AUTOCOMPLETION :(
/>
</LinearLayout>
</layout>
I've already try invalite cache and delete or override some folders but nothings seems to work for me.
After doing some digging i found out the following
Changing your LinearLayout to a ConstraintLayout solves your problem, but why?
ConstraintLayout is from a library (you import it via your build.gradle androidx.constraintlayout:constraintlayout:*.*.*)
CommonsWare explains it here android.support.constraint is from a library, not the platform.
Taking this into account Android Studio maybe doesnt understand the app namespace for layouts that belong to the Android platform like LinearLayout as they are part of the android namespace.
This is my interpretation, hope it answers your question
Faced same issue here what worked for me
Click Blue stack icon (present in top left corner of layout preview) -> Force Refresh Layout
Set Constraints by dragging constraints in Layout preview window once
Now suggestions should start appearing again.
I'm designing a pretty complicated form on Android, and I'm using includes in my fragment. I basically have this:
include_form.xml
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:orientation="vertical"
tools:parentTag="android.widget.LinearLayout">
...
<Spinner
android:id="#+id/desired_time_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:prompt="#string/time_desired_field"
android:spinnerMode="dialog"
tools:listitem="#layout/item_spinner_simple" />
...
</merge>
which renders beautifully on Android Studio's preview. However, when including this on another file, like this:
fragment_signup.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
...
<include
layout="#layout/include_form"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
...
</LinearLayout>
This renders well on a device, or a simulator, but it's not rendered correctly on Android Studio's preview: it basically ignores the tools:listitem attribute on the Spinner.
This works flawlessly for other components, such as a RecyclerView. Does anyone have an idea, or have I stumbled upon a bug? Thanks!
** Edit 1 **
Tried to add tools:listitem="#layout/item_spinner_simple" to the include tag and that didn't work.
** Edit 2 **
It really does seem that this is a bug. I've created a bug report:
https://issuetracker.google.com/issues/132686264
I searched a lot for this error but ended up seeing that everyone is suggesting of uninstalling android studio and reinstalling it with all sdk work which is not feasible to me. How can we remove this error in a decent way, please refer me to the answer if anyone has already given the right one.
Please use app instead of android.
app:layout_constraintWidth_percent="0.5"
Also, Add one constraint property like below:
app:layout_constraintStart_toStartOf="parent"
or
app:layout_constraintTop_toTopOf="parent"
your_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<Button
android:id="#+id/btn_temp"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintWidth_percent="0.5"
android:text="Hello World!"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Using Android studio 3.1, and I have a strange problem, I can't edit my UI,
I enter the content_main.xml, using the design tab, blueprint, anything i drag to the blueprint is not appearing, I use the infer constraints, still not helping
this is my XML code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/app_bar_main">
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="53dp"
tools:layout_editor_absoluteY="168dp" />
</android.support.constraint.ConstraintLayout>
I would't recommand using the UI designer, you don't get the feeling of what you are really doing with it. You should learn how to directly edit the XML file, this isn't really harder and at least you know what you are doing.
You must drag the widget to the component tree
ver imagen
I'm using Intellij IDEA 2017.2.2 for Android app development. I have the following layout file:
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/image_x"
android:id="#+id/text_x"
android:layout_marginStart="24dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBaseline_toBaselineOf="#+id/edit_image_x" />
...
</android.support.constraint.ConstraintLayout>
However when I open Design tab, I see that value of layout_marginStart is ignored and there is 0 in properties panel. When I try to set margin to other value, editor does not set layout_marginStart to new value, but creates layout_marginLeft what has no effect because there is still layout_marginStart.
This problem appeared after upgrade of Intellij IDEA from 2016.3 to 2017.2.2.
Is it a bug? How can I fix it? I don't want to remove all layout_marginStart from my code and replace it with layout_marginLeft. Is there any other solution?