Dynamically adding tabs to ViewPager with animation - java

Ive been looking around for quite a while but i cannot seem to find anything about this.
Would it be possible to animate adding a new tab to the viewpager?
I am able to add a new fragment to my pagerAdapter and call notifyDataSetChanged() to dynamically add of remove view from the TabLayout. However, I bet it would look much better if its animated.
Is this possible?
What apProach would be recommended for this?

Related

Android - Toolbar popup custom layout

Was wondering how you would go about implementing a custom layout for a toolbar popup, the one you get when you press on the settings button.
I need to increase the padding on the top and bottom of the popup, and also add in a custom font here. The only way I can think to do it would be to basically inflate a custom layout here but I'm not sure how it can be done. Most of the documentation I find online about it is just about styling it instead of adding in a new layout.
I thought maybe doing something like:
app:actionLayout="#layout/menu_settings_popup"
Would work, but unfortunately it doesn't. Also trying to set the layout and background in styles didn't
Would appreciate any help with this. Thanks
I think this would be what you need:
https://scriptedpapers.com/2015/02/12/android-action-bar-and-overflow-menu-customization-with-theme-appcompat/

How to Add Rules to align views inside Cardview in Android

I have a cardview inside which I have several Views which I want to align one below another. For a relative layout I will use the following
layoutParams.addRule(RelativeLayout.BELOW, idofanotherview);
However I cannot find addRule() method for cardview, how do I achieve this?
As the documentation of the CardView states, this component inherits from FrameLayout. That is normal that the addRule() method is unrecognized.
If you really need to use a RelativeLayout to position your subviews then I suggest that you wrap your subviews with one.
This post gives you a good exemple of how to achieve what you need
Good luck!

Create multiple horizontal scrolling layouts within a scroll view

So I have a Scroll View which contains a relative layout. I want that relative layout to have 3 or more layouts that can be scrolled. I know how to implement that with HorizontalScrollView, but before execution, I have no idea how many elements the HorizontalScrollView is going to have. Should I use ViewPager for this? What I would like the most is a HorizontalListView.
Would you recommend something like this:
https://github.com/sephiroth74/HorizontalVariableListView
Or should I add views programmatically in a HorizontalScrollView?
ScrollView is widget that should be used to keep static layouts inside. In general - ones that just are ~slightly bigger that the screen.
If you need something really dynamic you should use elements based on adapters like ListView, or ViewPager.

Swipe image in Listview

I want to swipe an image from left to right and right to left in an ListItem, I searched so many codes in online, none had solution for me, can anyone help me.
If I understand you correctly, you're looking for something like a ListView that swipes horizontally instead of vertically.
You want a ViewPager:
Here's an example:
http://developer.android.com/training/animation/screen-slide.html
On the adapter's instantiateItem() method (which more or less takes the place of the getView() method in the ListView adapters), simply inflate layouts that contain only your images, rather than text like is shown in the example.
http://developer.android.com/reference/android/support/v4/view/ViewPager.html

Multiple TextViews in a SurfaceView

I am creating an android game, I tried using the canvas.drawText() method to display my score and level but it caused errors. Now I am trying to use TextViews to display them, I am using a SurfaceVeiw and I wanted to know is it possible and would it be a good way of doing it.
You can't really put TextViews into a SurfaceView. What you can do instead, though, is add TextViews on top of the SurfaceView. Let me know if you need help on doing that if you don't know how.
// You can use a FrameLayout to hold the surface view
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.addView(surfaceView);
// Then create a layout to hold everything, for example a RelativeLayout
RelativeLayout relativeLayout= new RelativeLayout(this);
relativeLayout.addView(frameLayout);
relativeLayout.addView(textview1);
relativeLayout.addView(textview2);
setContentView(relativeLayout);
When adding your views, it may be helpful to using LayoutParams to help organize things. Use this documentation for LayoutParams. Hope this helps!
If you're using an XML layout, I would use a RelativeLayout, as mentioned above, contain the SurfaceView inside a FrameLayout. Placing the TextView's on top of the FrameLayout is just a simple matter of configuring the RelativeLayout parameters for each view. You seem new to Android, perhaps this guide will help you with RelativeLayouts and XML layouts in general.

Categories