Display view like a spinner's list without relativeLayout - android

For some reasons, I have to create a kind of custom spinner. I meam, I want to display a Button/an ImageButton and onClick on it, I want to display a list. But this list must be floating like with a spinner.
The problem is I haven't and I can't add a RelativeLayout as a parent.
So how can I add a view floating on the top and looking like a spinner's list ?
I need you ! :D

You can use PopupWindow and use showAsDropDown method to show it at any location you want, in your case make use your Button/ImageButton as anchor view.
you can follow this

Related

Android: Detect if user touches a view inside parent view

I have 40 ImageViews inside a GridLayout, they have different colors and I want to know if user touched the desirable image or somewhere else(for example if user touched red image). How should I do that?
Set an OnClickListener for each view and store the views. In onClick you can check the view and know what ImageView was clicked. You could also think about changing the type to ImageButtons!
If you have further problems with your Grid not being able to be clicked, check this out: http://cyrilmottier.com/2011/11/23/listview-tips-tricks-4-add-several-clickable-areas/
TLDR: Disable focusing of the views in your layout.
If you manage your images in a collection maybe think about switching to gridview and implement an adapter with an itemClickListener. So depend on which item is clicked do you action.
How GridLayout items come from the Adapter(List/Image) in Android App

Add or Remove ImageView dynamically

Is there any way to add or remove android imageview in UI dynamically ? I have 2 objects : List view and image view. I want to show each other dynamically without crashing each other.
when you want to show listView and hide ImageView, you can follow below code.
listView.setVisibility(View.VISIBLE); // showing listview
imageView.setVisibility(View.GONE); // hiding imageview
you can choose which one to show and which one to hide.
You can have both loaded from xml and then keep playing with View.VISIBILITY set it to GONE to hide and VISIBLE to make it vsible again.
So can either implement idea suggest by above.
Or for more cleaner code you can put elements in different layout and make the complete layout as visible or hidden whenever a certain event is being triggered!!
Hope this helps....!!!
You can put listview and imageview into FrameLayout and switch visibility

Create a Dropdown to show more Views in Android

I am trying to code a layout, but I do not know well how to approach it.
Initially I have the following:
When the user click in this View, I need to show:
I thought I will need a Spinner, but the content that is shown when the user click is not a list but a set of Views (In this case, it will be a LinearLayout with a Spinner and a EditText).
I am a little lost, what would be the best approach to achieve this?
Do I need to implement a CustomView?
Sorry if it is a dummy question, but I can figure out how to code this Layout.
I think the best approach would be to make a LinearLayout in wich you can place you Spinner and your Search EditText and set this LinearLayout ViewGroup setVisible(View.INVISIBLE).
Then when you click on the "registra alimento" View set the LinearLayout below to setVisible(View.VISIBLE)
To fade it in:
Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
viewToAnimate.startAnimation(in);
viewToAnimate.setVisibility(View.VISIBLE);
Take one Linear layout add Textview of Registrar alimento than set linear onClickListener with visibility of Spinner and edittext.(Also maintain flag for visible invisible )

Tooltip on the screen

I want to implement tooltips to be shown near some Views in my application. How is it possible to show some views over existing layout? How to position it where I need?
Use a PopupWindow, you can show it at any position with it's showAtLocation() method.

Nested text view in android,with dynamic content

I want to display a recursive or nested text view at depth of 3 in Android.The text to be displayed is, dynamic coming from web service.
for example:
If I Click on Help(Level 1)
it'll show topics under Help
If I Click on Help_Topic_1(Level 2)
it'll show questions under Help_Topic_1
If I click on this question, say HT_Question_1(Level 3)
it'll show Answer of that question(Level 3)
how to accomplish with this? please guide me.
You should use ExpandableListView. Reference http://developer.android.com/reference/android/widget/ExpandableListView.html
You can call expandGroup and collapseGroup methods for expanding and collapsing on clicks.
the simplest way to do this is to have a nested layout structure. Your root view will contain the button to show level 1 and a child layout and initially be visible. The children's layout visibility will initially be set to "GONE". In the onclick listener for each button you change the visibility of the layout below it to view to "VISIBLE".
This of course is a very simple way of doing it. If you require to have open and close animations you'll need to use a more complex method.

Categories

Resources