How to reference a layout schema - android

In Android Studio I have the following layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/entry_entry"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:paddingRight="4dip"
android:textSize="8pt"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dip"
android:layout_weight="0.42"
android:layout_height="wrap_content"
android:gravity="right">
<TextView
android:id="#+id/distance_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="2dip"
android:textSize="8pt"/>
<TextView
android:id="#+id/miles_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="2dip"
android:text="m"
android:textSize="7pt"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/folder_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="4dip"
android:textSize="6pt"/>
</LinearLayout>
<TextView
android:id="#+id/file_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="6pt"/>
</LinearLayout>
This layout is copied from an app that worked in Eclipse.
When I "Validate" the xml file I get the following errors:
Error:cvc-elt.1.a: Cannot find the declaration of element
'LinearLayout'.
Error:External resource http://schemas.android.com/apk/res/android is
not registered
Error:Premature end of file.
It seems that the answer will be to register the schema. How do I do that? (I have googled that question but not found an answer.)

There is no XML schema for layout resources. That is because there is an infinite number of element names (based on arbitrary Java classes) and an infinite number of attribute names.
On the whole, I am not aware of an XML schema for any Android resource type. Layouts are the type most resistant to having such a schema, though.

Related

Why is the graphic layout erroring on "android:"

I just started my first android app following Big Nerd Ranch Android Programming book and in doing the first exercise it has me enter the following XML:
<LinearLayout xmlns:android="http://schema.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:text="#string/question_text"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/true_button"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/false_button"
/>
</LinearLayout>
</LinearLayout>
However, when I switch back over to the graphical view it gives me a bunch of errors like:
"<LinearLayout>" does not set the required layout_width attribute:
(1) Set to "wrap_content"
(2) Set to "match_parent"
When I click to set it to one or the other it changes my XML to be:
<LinearLayout xmlns:android="http://schema.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android1:layout_width="match_parent"
android:layout_height="match_parent"
android1:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
Why is it insisting I use android1: and not accepting android: for any values?
Remove this line:
xmlns:android1="http://schemas.android.com/apk/res/android"
You have a typo in you xml namespace declaration:
xmlns:android="http://schema.android.com/apk/res/android"
should be
xmlns:android="http://schemas.android.com/apk/res/android"

unfortunately app stop working: Failed to find style 'mapViewStyle' in current theme

I saw so many answer of this question here but not one solve my problem. I am trying to make a tab layout I which there is text is text view in table layout and below table layout I want to add map. and I'm trying to do this but not get the result.
my error is
Failed to find style 'mapViewStylr' in current theme
after adding the MapView I got this error. and when I run the code on Nexus one and try to open the layout in which I added the MapView then the application Unfortunately stopped.
here is my layout code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/white"
>
<ScrollView
android:id="#+id/info_tab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:id="#+id/venuinfolayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/white" >
<TableLayout
android:id="#+id/venuetable"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:fitsSystemWindows="true"
android:weightSum="2"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="#+id/venueaddress"
android:text="Address:"
android:textColor="#android:color/black"
android:padding="6dip"
android:textStyle="bold"
android:textSize="20dip" />
<TextView
android:id="#+id/venueaddress_details"
android:layout_height="wrap_content"
android:layout_width="180dip"
android:singleLine="false"
android:layout_toRightOf="#id/venueaddress"
android:textColor="#android:color/black"
android:text="text"
android:layout_marginLeft="10dip"
android:padding="6dip"
android:textSize="15dip"
/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="#+id/venuephone"
android:layout_below="#id/venueaddress"
android:text="Phone:"
android:textColor="#android:color/black"
android:padding="6dip"
android:textStyle="bold"
android:textSize="20dip" />
<TextView
android:id="#+id/venuephone_details"
android:layout_below="#id/venueaddress_details"
android:layout_toRightOf="#id/venuephone"
android:text="number"
android:textColor="#android:color/black"
android:layout_marginLeft="10dip"
android:padding="6dip"
android:textSize="15dip" />
</TableRow>
</TableLayout>
<com.google.android.maps.MapView
android:id="#+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/venuetable"
android:clickable="true"
android:apiKey="AIzaSyAvWazTUUQr88b_UqQvB4k5rPAtOhlxTFA" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
//try this it may help you
Add this into your manifest file
<uses-library android:name="com.google.android.maps" />
I had the same problem when I try to build a simple app, following the Android MapView tutorial.
The app showed this exception in AVD for the file file main.xml:
Failed to find style 'mapViewStyle' in current theme
At last I found that there is a mistake in file AndroidManifest.xml:
The element should be a child of the element, not immediately within .
Hope this was any help to you.
OR
look Here

Android layout or button

I'm having a problem with an Android APP that seems related to layout. Attached image you'll see that the "Alerts" button sticks out and doesn't seem the same as the other buttons. I've replaced the image with a known good one, but the problem remains.
It was suggested it was because it is tabhost layout, but all the changes that have been recommended have not worked. So far I've tried changing the attributes from android:height and width to "wrap_content", "fill_parent", and "match_parent". Match caused another strange white space to be corrected, but this button is my last apparent challenge.
Here's the layout code, can you tell me what the problem is?
<?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" >
<Button
android:id="#+id/btnSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/job_tab_bar_search"
android:focusable="false"
android:freezesText="false"
android:imeOptions="actionNext"
android:longClickable="false"
android:paddingLeft="17dp"
android:text="Search"
android:textColor="#color/color_text_default"
android:textSize="12dp"
android:visibility="visible" />
<Button
android:id="#+id/btnHistory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/job_tab_bar_history"
android:paddingLeft="25dp"
android:text="History"
android:textColor="#color/color_text_default"
android:textSize="12dp" />
<Button
android:id="#+id/btnFavorites"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/job_tab_bar_favorites"
android:paddingLeft="30dp"
android:text="Favorites"
android:textColor="#color/color_text_default"
android:textSize="12dp" />
<Button
android:id="#+id/btnAlerts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/job_tab_bar_alerts"
android:paddingLeft="12dp"
android:text="Alerts"
android:textColor="#color/color_text_default"
android:textSize="12dp" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.32" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TabWidget>
</LinearLayout>
</TabHost>
You'd think someone would have replied, in the end it was stupid simple.
The answers is:
Tabhost using tabactivity will display the background through menu items if they are re-sized. Add a color coded (html notation) color to the schema, then call that with the android:border-background construct.

why can't I override layout properties of included layouts in my Android project?

I am attempting to create some modular UI elements as described at Android Developers - Creating Reusable UI Components, unfortunately I'm not getting the desired result.
The article states:
you can override all the layout parameters. This means that any android:layout_* attribute can be used with the tag.
My XML code looks like this (relevant parts):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="#+id/radio_group"
layout="#layout/radio_buttons"
android:layout_marginTop="75dp"
/>
<include android:id="#+id/player_group"
layout="#layout/player_buttons"
android:layout_alignParentBottom="true"
/>
<EditText android:id="#+id/text_field"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter Your Login ID:"
android:layout_below="#id/player_group"
/>
Here is the first of the included layouts:
<RadioGroup
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/radio_group"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginBottom="20dp"
>
<RadioButton android:id="#+id/radio01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Song #1"
android:paddingLeft="45dp"
/>
[two more identical buttons]
<TextView android:id="#+id/choice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="you have selected:"/>
</RadioGroup>
and the other:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:text="btn01"
android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
/>
<Button android:text="#+id/Button02"
android:id="#+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
/>
<Button android:text="Start Playing"
android:id="#+id/startPlayerBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:onClick="doClick"
/>
</LinearLayout>
Unfortunately - this results in all the included UI elements bunched together on top of each other at the top of the screen. The EditText element aligns correctly, but none of the included elements will respond to any overrided attributes. I have tried a number of different ones with the same non-results.
Note: I also tried putting an android:layout_alignParentBottom="true" parameter into the included layouts thinking that it might need to be in there for it to be overridden, but got the same non-result.
also - the marginTop param doesn't do anything either.
So - any idea what I'm doing wrong?? This is driving me crazy!
Note: there was a question asked a little while ago about how to style included layouts, the answer was a reference to the page on Reusable UI Components. Just want to say that I have read that question and the answer and it hasn't helped.
There is a bug when using include where included layouts are not positioned correctly unless you specify values for android:layout_width and android:layout_height. Try this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="#+id/radio_group"
layout="#layout/radio_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="75dp"
/>
<include android:id="#+id/player_group"
layout="#layout/player_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/radio_group"
/>
<EditText android:id="#+id/text_field"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter Your Login ID:"
android:layout_below="#id/player_group"
/>

Android SlidingDrawer

I'm trying to put a Sliding Drawer to my activity using this tutorial. My app is for Android 2.1-update1 (API 7). When i create a xml layout like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<SlidingDrawer
android:id="#+id/slidingDrawer"
android:handle="#+id/drawerHandle"
android:content="#+id/contentLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center">
<EditText android:text="" android:id="#+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="100px"/>
<Spinner android:id="#+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:prompt="#string/strFilter" />
<Button android:text="Filtriraj" android:id="#+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
</SlidingDrawer>
<ScrollView android:layout_height="fill_parent" android:layout_width="fill_parent">
<TableLayout android:layout_width="fill_parent" android:id="#+id/tableLayout1" android:layout_height="fill_parent" android:orientation="horizontal">
<TableRow android:id="#+id/tableRow1" android:layout_height="wrap_content" android:baselineAligned="true" android:layout_gravity="center_horizontal" android:clipChildren="true" android:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_margin="3dip">
<TextView android:clickable="true" android:layout_height="wrap_content" android:text="#string/lblOd" android:id="#+id/textView1" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:layout_marginRight="5dip"></TextView>
<TextView android:clickable="true" android:layout_height="wrap_content" android:id="#+id/textView2" android:text="#string/lblDatum" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:drawableLeft="#drawable/arrowdown"></TextView>
<TextView android:clickable="true" android:layout_height="wrap_content" android:id="#+id/textView3" android:text="#string/lblTekst" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:layout_marginLeft="3dip"></TextView>
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
I got an exception when switch to "design view" - Graphical Layout. Error is
ClassCastException: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be found: - SlidingDrawer
What's wrong with my code?
Switch design view to Android 3.0 then it works, somekind of a bug in ADT. If you run it in emulator, then code works.
Unfortunately, you'll be designing/laying out things for 3.0, when your app will be running on MILLIONS of 2.x devices instead.
Fully qualifying the SlidingDrawer class name (android.widget.SlidingDrawer) resolved this issue for me. This only seems to work for 2.1-update1 and above however.
Also, be sure that you set the drawer handle to a valid child of the drawer.

Categories

Resources