I tried to write a test demo for Google Map V2 in Android Studio. I followed every step from Androidhive Google Map V2 or better I think I need.
I'm using the same layout_main.xml
<?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="fill_parent" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
but I'm getting always the same rendering problem:
Rendering Problems
A <fragment> tag allows a layout file to dynamically include different layouts at runtime. At layout editing time the specific layout to be used is not known. You can choose which layout you would like previewed while editing the layout...
I have absolutely no idea what's the problem. Did I forget something?
I just need to add Google services in the build.gradle like
compile 'com.google.android.gms:play-services:4.4.52'
I copied the manifest from the demo and changed the API Key.
The accepted answer is not wrong but it does not help.
As Dan wrote, Android Studio (also Version 1.0) will not display the map.
Maps needs an API key and dynamic processed code, maybe some day we will have that but so far not.
I've a 5 minute solution for those who want to see their app properly in layout preview:
To properly develop I still needed something else than a blank background.
I added overlays and buttons on top of the map, I really needed to see the map while placing elements over it.
The solution is simple:
1. Make a screenshot of your app with the map running (Power + Volume Down)
2. Download the screenshot and use an image editor to remove the top and bottom UI elements, so you will end up with only the map itself as an image.
3. Import that image into android studio drawables
4. create a new layout, name it dummy_mapviewfragment, put only a linearlayout and an imageview in
5. make the imageview "fill" the parent, and set "src" to the cropped image you just imported
6. back to your layout, add this into your Mapview Fragment xml :
tools:layout="#layout/dummy_mapviewfragment"/>
That's it, now you will have a non-interactive mapview fragment which displays a real map.
Your app will look like it looks on your mobile phone.
If you made errors in your image cropping you can "fix" it by setting the image scale to "centerCrop" so it will properly stretch out.
Update: You can get a screenshot without need to crop directly from within Androidstudio! Makes it a bit more convenient ;)
Rendering Problems
A tag <fragment> allows a layout file to dynamically include different layouts at runtime. At layout editing time the specific layout to be used is not known. You can choose which layout you would like previewed while editing the layout...
This is just the preview window telling you that it can't display a preview for the <Fragment.../> tag, because it doesn't know what kind of fragment you're going to put in it. You can safely ignore that message - your actual app will render the fragment fine when you run it (as long as you code it up correctly!).
Android Studio automatically offers a solution within the error description, which is adding the name of the fragment layout.
tools:layout="#layout/fragment_my"
Add a dummy layout "#android:layout/simple_gallery_item" as:
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="317dp"
android:layout_height="385dp"
android:id="#+id/map"
tools:context="com.example.XYZ.googlemaps.MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:layout="#android:layout/simple_gallery_item"/>
Related
I am participating in the Udacity Android Basics degree. I am struggling with the project explained below. I am yet using only basic knowledge so please do not be surprised by the code simplicity. :)) I am eager to understand how to position elements so that they appear in every phone orientation mode using RelativeLayout.
You can find the XML here.
There are two screenshots of the app displayed in portrait and auto-rotate. The portrait looks alright but in auto-rotate half of the information displayed disappears.
My second question is related to the clickable elements. Once, I made them clickable they turned into red and underlined. Is this common or I should offset this with another statement?
This is my GitHub project.
Any help is appreciated.
Thanks,
Iva
For Your First Issue of Portrait and Landscape Try to put your view contents in a scrollview so that the screen contents will be scrollable when the height of the view is more than the screen height (In Portrait and Landscape Modes)
Sample with your code
<ScrollView
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.android.helloandroid.MainActivity"
android:background="#03B3E4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Add Your Contents Here ...
</LinearLayout>
</ScrollView>
For the Second question
Textviews with android:autoLink="" always takes the color from your colorAccent in styles.xml in your project if it has text that can be linked like website or mobile or map
you can change the text color by adding android:textColorLink="yourcolorhere"
to your textviews
Thanks
For auto-rotation, you can either lock rotation for your app locking screen rotation. You can use any of the methods suggested by other developers.
But If you want to add landscape orientation to your app, then you will have to define a separate XML layout file for it. You can do so by Creating a
layout-landdirectory by right clicking layout under res and putting the landscape version of your layout XML file in that directory. You can also refer to this answer for some help handle screen rotation without losing data in android
Coming to the second part of your question, if you make an element clickable, it is not supposed to turn red and underlined. I am not sure how you are making them clickable but to make an element perform a function on Click, just declare the element and define it. Then you can set an OnClick listener to it. You can see an example here making a button clickable. Youcan also try this code to make the button clickable:
Button btn= (Button) findViewById(R.id.button_main);
btn.setClickable(true);
I am, at the moment, trying to make a google maps app using android studio.
Right now, everything is fine, except for one thing, when i go to the "Design" Tab, in the XML file i have this Redering message:
Rendering Problems A tag allows a layout file to
dynamically include different layouts at runtime. At layout editing
time the specific layout to be used is not known. You can choose which
layout you would like previewed while editing the layout...
And the main problem is that I cannot use any of the gui components in my layout, I searched about my problem and i understood that with this error, people couldn't see their map but they could put on textfields, widgets, layouts, etc.
But for me, my preview is completly frozen and i can't do any modification.
Picture of my android studio page.
As you can change the fragments dynamically with your code, android studio doesn't know which layout to show in design time. This is the reason of your error.
To specifically tell android which layout to show, add tools:layout="#layout/Your_layout_name" attribute to your fragment.
There is also a shortcut link below the error description which you have told. Just click on the link and android will add it for you and you will see the fragment in your layout with no rendering error messages.
For a detailed example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context="com.example.insane.fragmenttest.MainActivity">
<fragment
android:id="#+id/testFragmentID"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.insane.fragmenttest.WorkOutDetails"
tools:layout="#layout/fragment_work_out_details" /> <!-- This is the line you want to add. -->
</LinearLayout>
Try using Designtime Layout Attributes. http://tools.android.com/tips/layout-designtime-attributes
These attributes guide Android Studio on how to render run-time attributes in the layout editor.
I think you should include tools:showIn="#layout/activity_maps" in your the <fragment> part of your google_maps_api.xml
Just use this design for the fragment. This solved my problem. Also, refer to this link
<fragment
android:id = "#+id/ma"
android:name = "com.google.android.gms.maps.SupportMapFragment"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context = "com.example.demomaps.MapsActivity"
/>
Yes I solved this easily..Simply ignore the message and click line that is showing below of the rendering messages.
Actually fragment contains layout inner and if its not include its showing warning that it must contains you can simply ignore this message below the warning then this rendering issue will be resolved.
I recently made the switch from Eclipse to IntelliJ IDEA 12. Is there a good way to preview a fragment being used in another xml layout file?
In Eclipse there's a way to specify which fragment I'm using which is pretty helpful.
Edit (clarification):
What I'm referring to is the ability to view a Fragment being referenced in another xml layout. Say I'm creating a Profile screen (activity_profile.xml) and want to include a fragment (fragment_pic.xml) that contains a picture, name, etc. When I include the fragment in the activity_profile.xml, it doesn't display in the preview for the activity_profile layout. It just displays "<fragment>"
You can do this in the XML:
<fragment
android:name="com.yourpackage.yourapp.yourfragment"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:layout="#layout/fragment_layout"
</fragment>
The tools namespace is qualified by this in the top view, same as xmlns:android namespace qualifier:
xmlns:tools="http://schemas.android.com/tools"
I had this same issue as well after moving from Eclipse to the Android Studio Preview though thankfully Android Studio suggests you provide this in the XML when it checks your definitions, very handy :)
I think you mean the GUI designer. To switch between xml view and designer view, click on the buttons circled in red.
I have a layout menu which contains this:
<RelativeLayout android:id="#+id/computersMenu"
android:layout_width="50dp"
android:layout_height="50dp">
<include layout="#layout/component_add_button"
android:id="#+id/imagebutton_add_client"/>
</RelativeLayout>
component_add_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/ic_menu_add"
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="center"/>
Looking at the preview (EDIT: I mean the "Graphical Layout" tab of the xml editor in eclipse which uses the same rendering engine as all devices AFAIK) of component_add_button.xml you can see the image. Great. On the page which is including it it isn't displaying (although it does give you a selectable space where the image should be).
This seems like a really simple example that "should just work". The include tag has always seemed really flaky to me - I'm wondering if I'm missing something in terms of how it actually works...?
As your answer states, the eclipse preview does not display included layouts.
The simplest way to avoid doubt or mistakes in markup when "including" layout's is to design in the original layout then right click the view you wish to extract and select Extract include... from the menu
On a device this functionality worked fine. This seems like a bug in the "Graphical Layout" tab of the layout xml editor shipped with android-sdk.
I have a widget layout xml which sets the src to the delivered android widget 4x1 frame image.Here is the widget layout code.
<?xml version="1.0" encoding="utf-8" ?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tuwidget" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="#+id/tuwidget_img_btn"
android:src="#drawable/widgetinitial"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</AbsoluteLayout>
#drawable/widgetinitial holds the widgetinitial.png image example 4x1 at developer.android.com (AppWidget design guidelines).(4x1_Widget_Frame_Portrait.psd) What I am trying to do is display an image inside the delivered frame instead what happens is the frame image goes away and only the image I am trying to display shows up. How can I display the image inside the bounding box or the background?
Any help is much appreciated.
Another question - I think I saw in a couple of forums AbsoluteLayout is a deprecated feature for Android 2.1 and above. Is that correct? and does using AbsoluteLayout throws any force close or other exceptions?
AbsoluteLayout is deprecated. It doesn't throw any exceptions, but its generally a bad idea to use it because it is really hard to design a layout that will work on all screen sizes. There is generally a better way to do it using a different layout.
In your case, I don't follow exactly, but it sounds like you want to layer two widgets on top of each other? An image with a frame? To do so, I'd use a FrameLayout. This is designed for having multiple layers of images.
Common layout objects is also a good guide to the basic layout types.
Take a look at the end of the page 2 of this pdf