I try to use GridLayout in my App, but it wont work.
I used this Tutorial: IntelliJ and android.support.v7.widget.GridLayout
But it still wont work.
I get the following Error:
error: No resource identifier found for attribute 'columnCount' in package 'android'
error: No resource identifier found for attribute 'rowCount' in package 'android'
Any further tips?
EDIT:
work with my actual XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:grid="http://schemas.android.com/apk/res-auto"
android:layout_width="350dp"
android:layout_height="fill_parent"
android:orientation="vertical">
<EditText android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:cursorVisible="false"
android:id="#+id/txtName"/>
<android.support.v7.widget.GridLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
grid:columnCount="3"
grid:rowCount="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1,1" />
</android.support.v7.widget.GridLayout>
</LinearLayout>
Today I struggled with this and on android dev site I found simpler solution and why they're problems with it. GridLayout from v7 libraries aren't connected with v7 appcompat library so you must add v7 gridlayout library dependency manually.
If you use gradle then in build.gradle just add
dependencies {
...
compile 'com.android.support:gridlayout-v7:23.2.0'
}
and everything should works fine :)
You need to use the full package and class name:
<android.support.v7.widget.GridLayout>
And add the namespace so that other controls will use the default package:
xmlns:grid="http://schemas.android.com/apk/res-auto"
Related
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
I see the following in my activity.xml:
xmlns:app="http://schemas.android.com/apk/res-auto"
<android.support.design.widget.FloatingActionButton
app:fabSize="normal"
app:elevation="20dp"
app:layout_gravity="end"
app:pressedTranslationZ="6dp"
android:id="#+id/fab"
android:src="#drawable/xyz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
/>
My compiler complains as follows:
Error:(26) No resource identifier found for attribute 'layout_gravity' in package 'com.android.app'
app:layout_gravity="end" needs to be android:layout_gravity="end"
I'm not sure if a full list of Android XML Namespaces exists,
but in this case the layout_gravity attribute is part of the android: namespace, not of the app: namespace.
If you add the android namespace:
xmlns:android="http://schemas.android.com/apk/res/android"
You can then use android:layout_gravity as expected.
Change app:layout_gravity="end" to android:layout_gravity="end"
or if you want to add anchor gravity then use this:
app:layout_anchorGravity="end"
I was trying to porting the Tree-View-List-Android into my project recently. I have created a project called com.dotnetideas.treeview and added everything in. I can run the demo without any issue. But when I use it in another project, I kept getting “No resource identifier found for attribute 'indicator_gravity' in package com.dotnetideas.treeview” in main_demo.xml.
Here is the xml looks like.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:treeView="http://schemas.android.com/apk/res/com.dotnetideas.treeview"
android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<ListView android:layout_width="0dip" android:layout_height="0dip" android:scrollbars="vertical"
android:visibility="gone"> <!-- Just to test some attributes in IDE -->
</ListView>
<pl.polidea.treeview.TreeViewList android:id="#+id/mainTreeView" android:layout_width="fill_parent"
android:layout_height="fill_parent" treeView:indicator_gravity="right|center_vertical"
android:scrollbars="vertical" android:smoothScrollbar="true"/>
Although I followed the old code to changed the xml namespace from
xmlns:treeView=http://schemas.android.com/apk/res/pl.polidea.treeview
to
xmlns:treeView=http://schemas.android.com/apk/res/com.dotnetideas.treeview.
It doesn’t seem like valid xml namespace.
It turned out that the namespace needs to be
xmlns:treeView="http://schemas.android.com/apk/res-auto"
if we reference as a library project.
This answer from stackoverflow too didnt help.
I just updated my Android Studio and Android SDK, and now I can't do anything in my XMLs. It shows the same thing as previous, but I can't add anything and something got messed up.
Example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/bocterAppLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/bocterapp"
android:contentDescription=""/>
</LinearLayout>
It error says: "Element ImageView is not allowed here".
Do you have any idea why this has happened?
Cheers!
I had the same problem. Try to exchange the ImageView with the android.support.v7.widget.AppCompatImageView! That solved it for me.
I also had the same problem. In my case, I was using a container from the old support library. So changing
<android.support.constraint.ConstraintLayout ... />
to
<androidx.constraintlayout.widget.ConstraintLayout ... />
solved it for me - with no change to the ImageView.
I'am trying to load a spinner to my layout and keep geting this error:
The following classes could not be found:
- Spinner (Change to android.widget.Spinner, Fix Build Path, Edit XML)
heres my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Spinner
android:id="#+id/spn_dates"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="displayDatesToSpiner" />
<ListView
android:id="#+id/LST_bought_products"
android:layout_width="match_parent"
android:layout_height="302dp" >
</ListView>
</LinearLayout>
Thanks
This sometimes happens when you rename the standard AppTheme in your android manifest. It will build and deploy just fine, but the xml design editor won't render it.
This is usually because there's an invalid attribute somewhere.
Remove the onClick and it will work.