I am starting a new project in android.I have to make it like google maps.For example see the image below
The screen will be like this with 2 views.1st mark with red and other with yellow.
Now what i want is that when user drags view 2 from bottom to top it should be like this
How can i achieve this.Please do help me out as i new to andriod development
Thanks
Checkout AndroidSlidingUpPanel library, probably this is what you want to achieve.
There's a similar implementation in this library. Download the sample app here and see the
SlidingUpGridView
SlidingUpListView
SlidingUpRecyclerView
SlidingUpScrollView
SlidingUpWebView
options.
EDIT
Looks like AndroidSlidingUpPanel is a better solution.
EDIT 2
If you don't want to use that library, I suggest use the codes of that library. It's really not that much work.
Create a new package sliderlib or something in your project
Create two classes named ViewDragHelper.java and SlidingUpPanelLayout.java
Copy the contents of the two named classes here
Download these drawables to your drawable directory of your app
Add these values to your attrs.xml (create one if there isn't one)
And in your XML, use your new widget like this.
your_layout.xml
<your.app.package.sliderlib.SlidingUpPanelLayout>
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:panelHeight="68dp"
sothree:shadowHeight="4dp">
<!-- Your views to show in your Sliding Up Panel -->
</your.app.package.sliderlib.SlidingUpPanelLayout>
NOTE : The answer may not be exactly right. But it will be a start.
Related
I'm building my first app with Android studio and I'd like to use Material Design components such as cards in it.
I think I know how to add these by writing code, but I was wondering, is it possible to add cardview, recycleview etc. in design tab's palette somehow?
Whenever I used Android Studio to create material design apps, I always created the card through xml. It is then displayed correctly in the design view. However the widgets on the left hand side of the design view are only simple images, which are part of the actual Android API (do not need any extra references like in your case). To add a card to your page use the following xml:
<android.support.v7.widget.CardView
android:id="#+id/cardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:elevation="100dp"
card_view:cardBackgroundColor="#color/cardview_initial_background"
card_view:cardCornerRadius="8dp"
android:layout_marginLeft="#dimen/margin_large"
android:layout_marginRight="#dimen/margin_large"
>
//add any widgets which you want inserted in the card here
</android.support.v7.widget.CardView>
Code has been taken from here.
Hope this helps :)
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"/>
I would like to know if this kind of layout is supported under Android and what is its name.
The description:
the application is revealed by default in a main view and a menu will appear when making a "swipe gesture" from the margins to the center of the screen; usually this layout has to offer some kind of callback or manage to stop the underlaying activity for the application so the user can use the menu without interfering with what he is doing with the application itself.
Thanks.
If you are looking for a sliding layout, here is an example:
you can call it with:
<com.slidingmenu.lib.SlidingMenu
xmlns:sliding="http://schemas.android.com/apk/res-auto"
android:id="#+id/slidingmenulayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
sliding:viewAbove="#layout/YOUR_ABOVE_VIEW"
sliding:viewBehind="#layout/YOUR_BEHIND_BEHIND"
sliding:touchModeAbove="margin|fullscreen"
sliding:touchModeBehind="margin|fullscreen"
sliding:behindOffset="#dimen/YOUR_OFFSET"
sliding:behindWidth="#dimen/YOUR_WIDTH"
sliding:behindScrollScale="#dimen/YOUR_SCALE"
sliding:shadowDrawable="#drawable/YOUR_SHADOW"
sliding:shadowWidth="#dimen/YOUR_SHADOW_WIDTH" />
There is no built in function like that, so you have to use third party libraries
There is no built in functionality for this behavior. You'll need to make it yourself.
I am new to Android development, and have tried researching my question but can not find a suitable answer.
What I am trying to do is create a list of items, like the numbers 0-9 for example, and display that as a list that the user can scroll up or down to select the desired number, starting at 0.
The best example that I can think of is the HTC Sense timer, linked below (can not post pictures as a new user):
Sense Timer:
What I currently have is a Spinner, but that's not exactly what I want. I want the user to simply swipe up/down to make their selection, not press a button to bring up a drop-down list to make their selection.
Is there a simple way to do this that I am missing, or is it a fairly complicated thing to do? I have not been able to find an example on my own.
Thanks
This is simply known as Wheel View in android. I am not much aware of its implementation, but here is a very good demo. Take a look at it.
http://android-devblog.blogspot.in/2010/05/wheel-ui-contol.html
This will get you started with it.
Here is another one,
http://android-devblog.blogspot.in/2011/01/android-wheel-update-custom-views-for.html
Try ScrollView, may this will work:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
//Your Components
</RelativeLayout>
</ScrollView>
You need to use a listview and an adapter for this. Its a very simple way to implement the vertical scrolling list of items. Please refer the code from the following link:
http://developer.android.com/resources/tutorials/views/hello-listview.html
How to add a header to an existing android activity? All the examples that I found with a search engine are showing how to add a header to the list view.
I don't know what you are looking for..might be this answer is useful to you.
You have to add a view the xml that you're using for your layout. So for example, say your Activity is using a linear layout. You'd do:
<LinearLayout android:orientation="vertical" ....>
<LinearLayout....>
<!---- Header Stuff Goes Here ---->
</LinearLayout>
<!--- Rest of the layout for your activity goes here ---->
</LinearLayout>
What you are looking for is a ActionBar, it is included on 3.0 api but if you want to use with backward compatibility you can use different libraries, my preferit is GreenDroid you can also see an example downloading the GreenDroid Catalog App from Market.
I hope this helped you :)