Android implementing tabbed layout that you can swipe across - java

I am trying to implement a layout that looks like a tabbed view, but is it possible to implement it in such a way that if the user swipes horizontally, then it will switch to a different tab? A good example of this is the Google+ app for Android. In the streams Activity, there are three tabs (or subsections): Nearby, All Circles, and Incoming. Notice how when you swipe in one horizontal direction, the screen scrolls to the corresponding subsection. Is there a way to implement this?

You can achieve that with fragments and viewpager. you can use the things through android-support-v4 library. android-support-v4 library including the example matches your need.

Related

I want to build an Android app with overlay over the map, What layout should I use to achieve the result as the image?

enter image description here
Should I use fragments? but I want an overlay over the map activity. How can I achieve this?
So far, I have been trying, to add two buttons and on click of a button opens a floating map, but it doesn't give me this result, it resembles a bookmark bar on chrome with three dots on the sides which aren't what I want.
Not sure what you are going to do when user will tap on go back or any button or back press
but here i assume it that you are going to remove that white overlay and only map will be shown
if yes then you can simply use map in your activity/fragment whatever you like and white overlay should be created and shown using BottomSheetDialogFragment
to understand how you will create BottomSheetDialogFragment , you can refer this example
https://medium.com/#kosta.palash/using-bottomsheetdialogfragment-with-material-design-guideline-f9814c39b9fc
I think the best bet is using coordinatorLayout with a child layout that has BottomsheetBehaviour for the overlay. or simply BottomSheetDialogFragment if user isn't going to interact with map when the overlay is drawn up.
a layout with app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" fits the picture. more on that here

Android studio How to configure app for multiple layout for deferent screens sizes when can't use Wrap content?

I hit a brick wall trying to configure my app for multiple screens. I read a lot of information about it but so far I didn't manage to successfully do it. to begin with, I have to use hard-coded sizes for my buttons because there are many of them, 53 to be exact, and they have to be square, 40x40dp, and placed precisely on the layout. so I can't use wrap_content, fill_parent, etc' because then I can't fit all the buttons on the layout.
I've created 5 different layout 'activity_main.xml' with these screen configuration: normal_mdpi, large-hdpi, xlarge-xhdpi, xxhdpi, xxxhdpi. so far so good but if I don't apply (With the "device for preview" dropdown menu) a specific phone configuration to any of the layouts, then they won't fit on the screen. But then the layouts fit only for these phone configurations, they won't fit for one with a similar configuration but slightly different. what am I doing wrong? how many layouts do I need? do I need to create a layout for each phone out there?
You cannot use fixed sizes. I know you want to use fixed sizes, but you can't. Creating multiple layouts for each density is a common mistake. There is usually only one xml layout resource file for each activity, but there are exceptions when making really advanced layouts (fragments will be used).
How to fix the layouts
As the base layout inside the layout resource file, i suggest you use ConstraintLayout as it has a ton of potential and can easily make complex layouts. It will take some time to edit each view to make them use wrap_content or match_constraint (match_constraint is basically match_parent but for ConstraintLayouts), but it is necessary. Android will then take care of resizing and fitting the views for any density/screen size if you use wrap_content and match_constraint (match_parent for other base layouts like LinearLayout).
And remember, never use fixed sizes for views.

Three screens with vertical sliding ability

How is the best way to make three vertical screens with sliding between them, like ViewPager.
I want to show user middle screen with ViewPager for horizontal pictures sliding, and two screens for settings (top and bottom).
I tried to use ViewPager in ViewPager, but it's a bad solution for me.
Then ViewFlipper but could not make sliding between screens like ViewPager.
My last chance now is ViewDragHelper but I'm not sure.
Maybe somebody knows real example?

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.

Choosing an Android Layout

I am trying to achieve a specific layout in Android and I am not sure where to begin. The layout I am trying to get is something akin to this:
https://dl.dropboxusercontent.com/u/6116499/Layout.jpg
In this case, the black boxes will be containers of other components. Normally, in java I would create custom JFrames and attach them to a grid layout. I am not really sure if there is a corollary for Android. If there is, I am not sure what it is called. It is worth mentioning that the layout should be able to expand inward or outward with the components anchored to the outer edge.
So here is my question: What layout should I use? Furthermore, what control in Android functions as a collection of other controls like the JFrame does?
Thank you.
You can acheive the same using Relative Layout. Just that you would need to take care of components alignment in multiple layouts and phone factors. The other way of doing it is writing your own custom layout. There are multipe tutorials available for this.
This is one of them. You can also understand further from the youtube video posted. Google IO - Writing custom views

Categories