eclipse can not recognise my layout folder, my layouts could not be referenced by
R.layout.activity_qr01
and the error says:my layout can not be resolved or is not a field
the code of activity_qr01 is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world"
tools:context=".QR01" />
</RelativeLayout>
Your XML file is in the res/menu folder, it should be in the res/layout folder.
You are missing a </RelativeLayout> at the end.
Also, your file is called activity_qr01.xml, so you must reference it as R.layout.activity_qr01
Related
My user interface looks like that in landscape mode:
But I want to have them in parallel. so the should have width / 2 instead of height/ 2. So how can I change that?
My code looks like that:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/photo"
android:layout_weight="0.5"
android:id="#+id/btnTakePhoto" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/video"
android:layout_weight="0.5"
android:id="#+id/btnRecordVideo"
/>
</LinearLayout>
</FrameLayout>
Thanks in advance for your help!
Add layout-land folder in your res folder in app directory and design xml's with same name in this folder . Android frameworks will detects the mode and will select the layout file defined within layout-land folder .
*remember xml file name in layout and layout-land folder should be same .
I added an ImageButton to my CardView, and when I add app:srcComapat to my ImageButton. I'm getting an error like below:
Error:(27) No resource identifier found for attribute 'srcCompat' in
package 'com.example.jaisonjoseph.newsclient'
here is my content_main.xml layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.jaisonjoseph.newsclient.MainActivity"
tools:showIn="#layout/app_bar_main"
style="#style/Base.Widget.AppCompat.ButtonBar"
android:background="#ffffff">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="350dp"
android:layout_height="150dp"
app:cardCornerRadius="6dp"
android:background="#f6f6f6"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/daily"
android:id="#+id/imageButton3"
android:src="#drawable/daily" />
</android.support.v7.widget.CardView>
</RelativeLayout>
Just change RelativeLayout property
xmlns:app="http://schemas.android.com/apk/res-auto"
to
xmlns:app="http://schemas.android.com/apk/lib/com.example.jaisonjoseph.newsclient"
Edit :
add this
xmlns:app="http://schemas.android.com/apk/lib/com.example.jaisonjoseph.newsclient"
For more detail visit this : No resource identifier found for attribute ' ' in package 'com.app....'
Complete Code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/lib/com.example.jaisonjoseph.newsclient"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.jaisonjoseph.newsclient.MainActivity"
tools:showIn="#layout/app_bar_main"
style="#style/Base.Widget.AppCompat.ButtonBar"
android:background="#ffffff">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="350dp"
android:layout_height="150dp"
app:cardCornerRadius="6dp"
android:background="#f6f6f6"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/daily"
android:id="#+id/imageButton3"
android:src="#drawable/daily" />
</android.support.v7.widget.CardView>
</RelativeLayout>
what you are getting it seems like it's just a lint error that can be ignored.
you can use:
tools:ignore="MissingPrefix"
in your RelativeLayout to avoid seeing this error temporarily.
Because srcCompat attribute is actually defined within AppCompat library, so remember to add AppCompat library to your project.
UPDATE
For another reader how landing in this thread.
Do not use app's namespace using project name like:
xmlns:app="http://schemas.android.com/apk/res/com.yourproject.name"
Instead use:
xmlns:app="http://schemas.android.com/apk/res-auto" .
As it is said in https://code.google.com/p/android/issues/detail?id=9656#c71:
"Added support for custom views with custom attributes in libraries. Layouts using custom attributes must use the namespace URI schemas.android.com/apk/res-auto instead of the URI that includes the app package name. This URI is replaced with the app specific one at build time."
Read more at https://code.google.com/p/android/issues/detail?id=9656
I want to use switch button in my app. As its API is 11 and switch needs API higher than 14, I decided to use merge and include method but I get this error in values-v14/compound_switch.xml file : Element merge must be declerd. here are my files, what is the problem?
Main layout:
<include layout="#layout/compound_switch" />
layout/compound_switch.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:id="#+id/night_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView20"
android:layout_toLeftOf="#+id/textView20"
android:layout_toStartOf="#+id/textView20"
android:layout_marginRight="5dp"
android:checked="false" />
</merge>
values-v14/compound_switch.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Switch
android:id="#+id/night_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView20"
android:layout_toLeftOf="#+id/textView20"
android:layout_toStartOf="#+id/textView20"
android:layout_marginRight="5dp" />
</merge>
Move your layout that has the switch from the folder values-v14 to a folder called layout-v14. Layouts should be in the layout folder. The values folder is for colors, dimensions, attributes, etc.
I have an image in my main.xml as follows
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="70dp"
android:layout_height="70dp"
android:contentDescription="#string/hello"
android:maxHeight="70dp"
android:maxWidth="70dp" />
but I need to pass it to another xml file. Is this possible?
In your case you are having data reference.
Yes, its possible. Exists a tag called in android that you can "include" another android xml layout in other android xml file. I put a example using your main.xml
In layout2.xml ....
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include layout="#layout/main"/>
</LinearLayout>
More information about this tag, please check it out in the link below.
http://developer.android.com/training/improving-layouts/reusing-layouts.html
I tried to include admob to an Android app in Eclipse. But I get an error in the layout.xml. Eclipse tells me that com.admot.android.ads.AdView is an unbound prefix. I have the admob library included in the build path, following the pdf instruction. But it still does not seem to find the AdView class. But why?
Here is the layout producing the error:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah"
android:layout_width="wrap_content" android:layout_height="wrap_content"
>
<renegrothmann.kalah.GameView
android:id="#+id/gameView" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="2px"
/>
<com.admob.android.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
/>
</LinearLayout>
I had the same error wit this layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/topLayout"
>
<!-- Ad Placeholder -->
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a14df07c16f171a"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
/>
</RelativeLayout>
Then I made it:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/topLayout"
>
<!-- Ad Placeholder -->
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a14df07c16f171a"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
/>
</RelativeLayout>
Notice the second xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" in my RelativeLayout in the second example?
In fact if you remove the android namespace declaration xmlns:android="http://schemas.android.com/apk/res/android" it will start moaning about all the android components too.
Change the following
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
by
<LinearLayout
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
For me it's working with
<TableLayout
android:id="#+id/resultsuperlotto"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" />
Cheers!
Actually, you do not need to add xmlns:ads to a root element (or a parent element).
You can simply add xmlns:ads property to your AdView element, like:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
...>
</com.google.android.gms.ads.AdView>
Check this page.
Maybe you should replace "myapp" at the bottom with "app" or replace "xmlns:app" at the top with "xmlns:myapp". They should probably be the same.
I cannot provide a real answer, since actually I do not know, why it works now. What I did: I restarted with a fresh project. Sometimes, you simply go one wrong step!
Right Click your project, click Properties, click Android, on the Library panel click Add Button
and add both google-play-services_lib and appcompat_v7 libraries
Apply, Refresh, Clean under the Project.
If this doesn't work try the following:
Change the target line in project.properties as target=android-13
Right click on your project and Click Refresh
Click Clean under Project
Hope this will work.