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.
Related
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.
I have implemented a tabs and swipe method inside my application, Here's a link! (this is the nice tutorial)
inside my application in the first TAB I have a ListView and the row are defined in other xml.
this is tab1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/LinearLayout5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/LinearLayout3"
android:layout_alignParentBottom="true"
android:layout_below="#+id/LinearLayout3"
android:layout_marginTop="10dp"
android:background="#ccffcc"
android:orientation="horizontal" >
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<!-- tools:listitem="#layout/row"> -->
</ListView>
</LinearLayout>
</LinearLayout>
this is the row.xml
<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"
android:padding="5dp"
tools:context=".MainActivity" >
<TextView
android:id="#+id/tv_prodotto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="50dp"
android:text="Prodotto"
android:textStyle="bold" android:textColor="#000000" />
<View
android:id="#+id/viewLine"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_below="#id/tv_prodotto"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="#666666" />
<TextView
android:id="#+id/tv_qta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tv_prodotto"
android:layout_marginLeft="50dp"
android:layout_marginTop="3dp"
android:text="Quantita"
android:textColor="#000000"
android:textSize="12sp" />
</RelativeLayout>
the compiler give me an error in the tools:listitem
This is the error: Attribute is missing the Android namespace prefix
before implement the Tabs and swipe method (in a normal application) the tools:listitem="#layout/row" run correctly without compiler error!
How can I resolve this?
I will save you all the trouble.
I hope you're using the eclipse.
When you create new android project in Eclipse, they give you option if you want to implement tab swipe (many other options too).
While creating the new project, on very last window. They give you option for "Navigation Type". This is where you choose if you want to implement tab with swipe feature. To implement tab with swipe, your minimum API has to be 11.
Let me know how it goes, if you have any other question feel free to ask.
Hope this help you out.
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
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.
I am having issues with creating a menu (not menu when you click menu button -- but menu as in the welcome screen to select items). I went to ImageView and TextView float (left/right) Android and I did not solve my issue. I would like to create at least five or six options to select from on this menu class. This is my menu.xml file. Please let me know what I need to do.
The issue is that the first item appears, but the second item overlaps the first item. I been picking away with this for the last hour and cannot solve this issue.
<?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:padding="5dp">
<TextView
android:textSize="18dp"
android:id="#+id/message_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Check Your Account" />
<ImageView
android:src="#drawable/ic_menu_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/icon" />
<TextView
android:textSize="18dp"
android:id="#+id/message_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" View our Site" />
<ImageView
android:src="#drawable/ic_menu_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
thannk you.
Why don't you use a LinearLayout (like a vertical one with severals little horizontal ones inside, each with a TextView and an ImageView) ?
Anyway, if you want to use RelativeLayout you should use something like android:layout_toRightOf, android:layout_toLeftOf, android:layout_above or android:layout_below in your xml to place your elements.
I advise you to take a look at http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html if you don't know those parameters.
You use a RelativeLayout but you don't place elements with reference to each other.
Example :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="#+id/topBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Top"
android:layout_centerHorizontal="true">
</Button>
<Button android:id="#+id/leftBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left"
android:layout_below="#+id/topBtn"
android:layout_toLeftOf="#+id/topBtn">
</Button>
</RelativeLayout>
http://developer.android.com/reference/android/widget/RelativeLayout.html
A Linear Layout would be better.
Try this and tell me if this is what you needed:
<?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:padding="5dp"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/message_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Check Your Account"
android:textSize="18dp" />
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_add" android:layout_gravity="center_horizontal"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/message_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" View our Site"
android:textSize="18dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_add" android:layout_gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>