How to slide collection of views in circular way - android

I have four surface views and I want to show one at a time. If I want to see the next, I need to slide from right to left for next surface view. Its like film strip. What android component can be used to achieve this? Any direction will be grateful.

Maybe the InfiniteViewPager could help you : https://github.com/antonyt/InfiniteViewPager
In your layout, you can use :
<com.antonyt.infiniteviewpager.InfiniteViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
In your Activity , wrap your PageAdapter in the InfinitePagerAdapter :
PagerAdapter adapter = new InfinitePagerAdapter( ... a PageAdapter ... );

I think you should use TabSwipe functionality.
which ll help you to do slide from one view to other view Right to left and Left to right.
Read:
Tabs and swipe views
Horizontal view swiping with viewpager

Related

Only keep shadow at the bottom of the view

have this layout -
<Stepsview
android:background="#color/white"
android:elevation="#dimen/margin_16"/>
this cast shadow at the bottom as well as top :
and what i need is :
Steps view and ActionBar are 2 different views, one way I see is to combine these 2 views inside a view group and set elevation on the view group only.
Is there any other way only controlling steps view.
Achieved it by dynamically adding the steps to the top abbbar ( container for toolbar ) and setting the elevation to the app bar itself.

TabLayout first item offset on the left

I have a TabLayout with horizontally scrollable tabs using Material Design guidelines state.
On mobile and desktop, offset the first tab on the left to sign that tabs are scrollable.
How can I achieve this? If I add a left margin or padding this will only move in all tabs to the right side but I can't scroll the tabs all the way to the left side of the screen anymore.
I also tried this:
tabLayout.setScrollPosition(2, 0.2f, true);
Which would pre-select the 3rd item and offsets the sliding indicator by 0.2 which in the end looks weird and also doesn't actually move the first tab item to the right side on the screen.
Thanks for help in advance!
I found the solution. In the layout XML you can set the content offset with "tabContentStart".
Example:
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabContentStart="57dp"
app:tabMode="scrollable" />
Here is the solution in the happy and wonderful Jetpack Compose world :
ScrollableTabRow(
selectedTabIndex = ...
edgePadding = 0.dp
) { /* Your Tabs */ }

Putting a View on top of Scroll View while Scrolling down

Basically, I have a Scroll View and it contains several child inside Linear Layout. Now, I want to show a View constantly on the top of the screen when it is scrolled down.If it is scrolled up everything should be as it was earlier.
Can anyone just help me out? Any help would be appreciated! (Thanks in advance).
Define a ObservableScrollView class entends ScrollView.
Then write your layout xml like this:
<RelativeLayout>
<View/>
<ObservableScrollView>
</ObservableScrollView>
<RelativeLayout>
In ObservableScrollView class,focus on this onScrollChanged function.
Change the visibility of your target view by param 'y'.

One "list" below another inside a ScrollView

I would like to reproduce this layout :
The blue lists are not scrollable, but the red panel (probably LinearLayout) is.
I already tried two ListView but I don't think it is the good way to do this, it doesn't work.
I read an article that advised to add multiple items to a LinearLayout. But in doing so, how to handle events on a single item, or use a BaseAdapter ?
I know I'm a little vague, but I'm having a little trouble explaining what I really want, I started Android development a few days ago.
Thanks.
I don't think it uses any ListView.
You can probably create something like this by having the red panel be a LinearLayout or RelativeLayout that's inside a ScrollView, so that it scrolls.
Then the blue "list" is probably not a ListView if it doesn't scroll. I guess it's just a bunch of regular views. So, something like this (pseudo code)
<ScrollView>
<LinearLayout>
<whatever layout for the green cell>
<include layout="blue_cell>
<include layout="blue_cell>
...
</LinearLayout>
</ScrollView>
And then you just create a layout for your blue cell, see info here: http://developer.android.com/training/improving-layouts/reusing-layouts.html
If you have a variable number of blue cells, you can just have the ScrollView and LinearLayout in XML, and inflate the blue cells layout programatically and add them to the LinearLayout

is it possible to do transition animations when changing views in the same activity?

Suppose I have 2 XML files and my activity will setContentView the appropriate one based on some button press from the user. Is it possible to change the transition animation for the changing of content view?
So far I see super.overridePendingTransition() which is suitable for starting new activities, however my example does not start a new activity, it just changes the layout in the current one.
Mathias Lin has explained it very well.
You can always use default stock animations supplied by Android framework.
Heres an example code:
boolean isFirstXml=evaluatingConditionFunction();
LayoutInflater inflator=getLayoutInflater();
View view=inflator.inflate(isFirstXml?R.layout.myfirstxml:R.layout.myseconxml, null, false);
view.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right));
setContentView(view);
Call this from any of your activity which holds your Parent View.
For custom animations you can visit developer docs. Heres the documentation link.
Yes, you can apply an animation on almost any view you like. Just via view.startAnimation(animation);
Take the outer viewgroup of your respective layout (content view) and apply the animation to it. Depending what kind of animation you want to do, it might make sense to inflate/load both layouts but hide one of them and then swap. Please specify what kind of transition you have in mind.
For example: if you do an alpha transition, you would run the alphaAnimation on the current layout, when when the animation ends (AnimationListener), you set the content view to the new layout, and fade the content back in, via another alphaAnimation.
A better solution is using ViewFlipper: it is a FrameLayout, that can do animations when changing the views.
<ViewFlipper
android:id="#+id/[your_id_here]"
android:inAnimation="..."
android:outAnimation="..."
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
<!--Your first layout -->
</RelativeLayout>
<RelativeLayout
<!--Your second layout -->
</RelativeLayout>
</ViewFlipper>
Then, switch the views with setDisplayedChild(int) or showNext() or showPrevious. If you want to have different animation for left and right movement, you have to set inAnimation and outAnimation in the code before transition.
More complete example is here.

Categories

Resources