Creating autohide custom view in android - android

I am working on creating a custom view in android. I want to create an autohide custom view control.
This control will be holding other UI elements mostly buttons or icons. It has a small button which is mandatory, clicking which will slide the control in or out thus changing its visibility.
one should be able to add other buttons or icons to this control
The control can be placed only at the borders, which needs to be specified while creating the view.
I don't know how to start with it
Should I be extending the View class or ViewGroup class.

have a look at this
and then you have to add a dynamic layout to this drawer

I used a RelativeLayout and added a Button to the View.
When I call expandView() or collapseView(), I call mybutton.setVisibility() and let RelativeLayout know it has changed with this.requestLayout().

Related

How do I add a button to a "extends View" class?

Is it possible to add a button to a class that extends View? ""public class josh extends View "" If not how can I merge a button onto the view when it is referenced in my main activity? uhg please help....
Two ways:
Have both the button and your custom view as children of a FrameLayout, by which the button can be drawn over your custom view.
Don't have a real button. Instead, draw something that looks like a button, treat touch events specially if they're within its dimensions, etc. This is more appropriate for something like a game.
I believe you can do #2 but have a subclass of Button do the drawing, so that it performs exactly like a normal button and is just positioned/sized by your custom view, but I don't know how to do this.
If are wanting to add a button to a view at runtime check this preivoius question... How to add a button control to an android xml view at runtime?

Using a layout inside a layout?

Which is the best way to change the content inside a layout by pressing buttons?
I want 6 buttons and different content for each push.
I cannot use tab layout because i already used it so..
I would suggest using the gridview that is set up in API Demos. You can import it in as a new project from the Android SDK.
It works effectively like the list of 'All Apps'. However you can change the way it lays out the buttons/icons/text.
In an app I'm working on, I have a list of message types as buttons. Clicking a button changes the display to a layout for composing the selected message. To do this, I have a FrameLayout for the area I want to change. I reference this view as 'compose_content'. When I want to change the content, I run the following code:
compose_content.removeAllViews();
LayoutInflater.from(activity).inflate(R.layout.new_content,compose_content, true);
This will change the FrameLayout content to the content from the specified layout.
One solution can be to have all the 6 views inside your inflated xml and depending on the button pressed set the visibility of that particular view visible and the rest gone

How to make object overlay another object in Android layout?

What I am trying to do is to have a menu appear over listView. Just like in okCupid app :
when you click menu below the picture :
https://ssl.gstatic.com/android/market/com.okcupid.okcupid/ss-480-3-11
it extends itself over the background view :
https://g1.gstatic.com/android/market/com.okcupid.okcupid/ss-480-4-11
I have a feeling that this particular app is done in Sencha or JQuery mobile or similar technology but is it possible to get same effect in native app?
thanks
Most layout classes 'help you' by avoiding widgets to overlaps, but with the RelativeLayout you have more flexibility to create overlapping views.
To be sure the overlay view is on top, you can call ViewGroup.bringChildViewToFront() on the relative layout.
In your example the top view also has a partially transparent background.
Try using FrameLayout and add appropriate transperency for the view
I can look around for some example code later but the basic idea would be to have a MenuView class that draws your menu and animates in and out by setting the content of the menu visible or not.
Then just have all your content be on top of that MenuView by using the relativelayout align_parentBottom and set the content to above the menuview.

GridView in android

I have a gridview of images in android. When i click any item on it, i want to show a new set of items over it. This is the screen shot .
Can this be done using gridview? Also what should be the type of view which must come over the gridview? The background should become preferably faded.
I am not so sure if you can achieve the second view using a grid view. In the grid view AFAIK you don't have any option of specifying the location of the grid elements. It just arranges it from left to right and wraps around.
But here is how I would do it -
First view can be done using the grid
view, as you already know/done.
For the second view since you want the the first view to remain in the background, there are two ways to go about this -
First option
You can use a dialog, you can create your own custom dialog which has makes it translucent.
In this custom dialog you can add further elements like images.Custom dialog example. For details on how to make it translucent you can look the sample app in android sdk.
Second option -
Use a layoutInflater. Put all your views into it.
You can display one view on top of another using the visibility attribute of the view. Layout Inflater

android custom view how to draw button on top of the view

I am creating a android app using LunarLander as a example.
Now I need to create a few buttons which are drawn over the view.
I do not want them as a seperate layout above or below the view but in the custom view.
Is this possible or am I going to have to programmatically show the button images then detect the touch. The buttons I create using new never show on the app. I assume this is because I have overwritten the onDraw and the buttons are never drawn even though I call
super.onDraw(canvas);
I think you could use FrameLayout to show two layers - first would be your surface from lunar, and second is the layout with buttons etc. You could define everything in layout.xml file. Probably that is enough.
Regards!
If your view extends Linear/Relative/TableLayout, you can use view.bringChildToFront(child).
Use AbsoluteLayout & then in your ui thread set button.bringTioFront() & you are done!
watch this post Problem when using more elements in the ListView

Categories

Resources