I have created custom tab bars by following the post given below:
How to create a Tab-like UI in Android?
No I need to display a set on sub menu when the center tab (actually it is a button) is clicked. I need the sub menu to pop up like in this drawing (sub menu should be above my main layout):
I believe that this can be achieved by putting an additional layout above the custom tab bar in which a set of buttons can be placed one after another. But I am not sure which layout needs to be used and how I can get the same style in the drawing. Please help me to find a solution.
you're correct with just adding another layout above the button you want to open it, and then setting its visibility to gone until you want to animate in it.
a regular LinearLayout would work fine, and then adding 4 buttons to it would work as well, then you would want to make sure those buttons used the same styles as the built-in android menu buttons (or style it yourself) but check out some of the built in styles here
example:
your activity
<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">
//all your other activity layout stuff goes here
<!--add your new menu-->
<LinearLayout
android:id="#+id/my_menu_layout"
android:visibility="gone"
... />
<Button
android:id="#+id/menu_btn_1"
style="#android:style/Widget.Holo.ActionButton.TextButton" //as example of built-in style
... />
//more buttons
</LinearLayout>
then in your activity class, assign an onClickListener to the button that will toggle the menu and animate the view in
//animation xml you make
Animation inFromBottom = AnimationUtils.loadAnimation(this, R.anim.layout_in_bottom);
mMenuLayout.startAnimation(inFromBottom);
mMenuLayout.setVisibility(View.VISIBLE);
now your view will animate in and you can go about adding onClick listeners to the buttons
Related
How to add a custom view top the android navigation bar like above image. when user click on the action bar need to push the main content down and add the custom layout top of the action bar.please how to accomplish this any one suggest a solution
Thanks
Rahul
An easy solution would be to use those views in the actual ActionBar like this: http://developer.android.com/guide/topics/ui/actionbar.html#ActionView. And then take all your layouts and put them inside a RelativeLayout and set their android:layout_below="" to a layout that corresponds to the ActionBar you want to use. So in a step by step way:
Create an action_bar.xml that has the items you want your actionbar to have (ImageViews or Buttons, w/e)
Include this layout in all the Layouts you will use (or in your main layout if you're using Fragments to display content).Like this:
<include layout="#layout/action_bar"
android:id="#+id/action_bar"
android: ... />
Make your Layout position itself below this layout (Using a FrameLayout for example)
<FrameLayout
android:id="#+id/content_frame"
android:layout_below="#+id/action_bar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Include the ActionViews (Spinner and tabs) in the ActionBar like it's taught in the link up there.
Simple question, i have this code
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
...
<LinearLayout
android:id="#+id/insideLinearLayout1"
...
<TextField>
android:text='beforeClick'
...
<Button
android:id="#+id/button1"
android:onClick="updateExpression"
...
</Linear Layout
<LinearLayout
android:id="#+id/insideLinearLayout2"
...
<TextField>
android:text='beforeClick'
...
<Button
android:id="#+id/button1"
android:onClick="updateExpression"
...
</Linear Layout
</LinearLayout>
</HorizontalScrollView>
The idea, is to change the textField text property, when clicking the button on the same layout!
Ok for 2 is easy, just need the reference of each button and each textfield and change use the get and set method!
But i want to add more layouts dynamically, and grab each one's reference would be a hard task.
So two questions :
How can i grab the id of the Linear layout, that have the clicked button?
I want to handle the 'insideLinearLayout(1 or 2 depending on the clicked button)'id in the 'updateExpression'!
How can i add more layouts with the same widgets as the ones created manually?
Thank you in advance.
Best of codings!
1)Your onClick function is passed the view that was clicked. Every view has a getParent() function. You can use it to get the LinearLayout, then get the id.
2)Create them with the new keyword then add them to the parent layout. For something like this I would probably make a custom compund view holding everything you want to instantiate at once, so you can treat the entire set of widgets as one.
I need to do a Sliding Up View wich should slide up from the bottom of the screen when I click a button. It has to show on the bottom of the screen and I need to slide/drag it to the center of the screen. The images below explain it better.
almost like the AndroidSlidingUpPanel from "umano" which you can find here:
The problem is that I want the first child (The content of my View - an image for example) to fill all the screen and also I want the second child(the actual bottom bar) to be showed when I click a button. The images below explain it better. If there is not possible to do this by changing the AndroidSlidingUpPanel, how can I do that? I have never worked with views like this. I would really appreciate any tip or help. Thank you very much.
To hide or show panel, you can use
showPanel()
method.
To hide it try this:
SlidingUpPanelLayout slidingPanel = (SlidingUpPanelLayout) findViewById(R.id.sliding_panel);
slidingPanel.hidePanel();
To make it appe
SlidingUpPanelLayout slidingPanel = (SlidingUpPanelLayout) findViewById(R.id.sliding_panel);
slidingPanel.showPanel();
This is available only in v 2.0 of AndroidSlidingUpPanel (https://github.com/umano/AndroidSlidingUpPanel). As I know, it's included in android support library v13 now, but not sure if there is latest version.
You can check this library for dragging content from all four edges of the screen https://github.com/SimonVT/android-menudrawer
You can make a custom layout inside this menu drawer to get your expected result.
You can do it with AndroidSlidingUpPanel, just set visibility:
android:visibility="GONE"
on the 2° child of the view (the panel) and use .showPane() and .hidePane() on SlidingUpPanelLayout to show/hide the panel when you click the button.
The following library do it as well
https://github.com/Paroca72/sc-widgets
Inside you will find a widget named ScSlidingPanel.
This widget work different from the other and can be use and customize very easily.
You put it inside a RelativeLayout give an alignment and it will open from that side.. Left, Right, Top and Bottom or mixed..
In your specific case your must align your panel at bottom of the container and it will sliding from the bottom.
<!-- Define the container -->
<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"
tools:context=".MainActivity">
<!-- Sliding from top -->
<scapps.com.library.ScSlidingPanel
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<!-- HERE THE YOUR CONTENT -->
<!-- or you can load by setLayout method -->
</scapps.com.library.ScSlidingPanel>
</RelativeLayout>
Another important property that you can use right for your case is the handle size.
You can define an handle and define the beavior of it.. as your image above you used a button.. you can unsing an image and setting setToggleOnTouch() to true for open/close the panel touching on handle.
I'm trying to do something like the Jelly app to show multiple dialogs at once when a user clicks. Is there a way on Android to show multiple dialogs at once? So far I've only seen posts about having one dialog appear and then another based on user action. But I want them to all appear at once, similar to Jelly, and then have the user navigate through them using gestures.
Here's an image: http://www.8ms.com/wp-content/uploads/2014/01/view-answers-compose-answer-jelly.png
I figured this out --
Use a FrameLayout (http://blog.neteril.org/blog/2013/10/10/framelayout-your-best-ui-friend/) to overlay views and have the answers appear and disappear on click.
Specifically with the Jelly example - One view is the main view (with the user's question) and then another view is the secondary view (with all of the community answers).
The secondary view starts off as hidden, so only the main view shows.
android:visibility="invisible"
Then when the user clicks the question in the main view, your OnClickListener for the main view can programmatically change the visibility of the secondary view.
view.setVisibility(View.INVISIBLE);
So the questions appear on top of the question. You can adjust the size of the secondary/question view so that you can still see the question, like in Jelly app.
The layout of the community answers is: (see code sample below)
HorizontalScrollView
--> Linear Layout
--> Custom Views (this is where each answer is shown. It could also be a Custom Dialog)
This is all within the FrameLayout.
On how to create a custom Dialog: http://about-android.blogspot.com/2010/02/create-custom-dialog.html
In your XML file, you would leave a blank space within the Linear Layout so that you could programmatically add in the answer views/dialogs because the number and content of the custom views would differ from question to question.
<HorizontalScrollView
android:id="#+id/notes_hsv"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_marginTop="100dp"
android:visibility="invisible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- AnswerViews are added programmatically to this LinearLayout -->
</LinearLayout>
</HorizontalScrollView>
On adding views programmatically to a LinearLayout: Android: Add a textview to linear layout programmatically
I have a main layout being hosted by an activity (setContentView method).
I have a button in the layout. I want to be able to click this button and a new layout will slide down from the left/top until the middle of the screen. So, the screen now will have two layouts where one is on top and another one is just beneath it.
This is something like the UI in Android Jelly Bean where you can pull the settings layout down using a touch gesture.
What are the possible implementations?
A method I have tried:
add the slide down layout into main.xml but set its visibility to gone
when button is clicked, run some code that will set the layout visibility to
VISIBLE and add some animations.
the result of this implementation is that this layout will push the rest of the
views down in order to have a "squeeze" space for itself which is not
what I intended to do (see above)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<LinearLayout
android:id="#+id/PR_slidedown" <---this is the intended slidedown layout
android:layout_width="8dp"
android:layout_height="40dp"
android:visibility="gone"
android:orientation="vertical" >
</LinearLayout>
....
Your implementation is partially correct, the other part is to host your two layouts in a FrameLayout so they can overlap with each other. Search for FrameLayout in here, there are a lot of example on how to use it.
Or try the SlidingDrawer