well, I think it may be not solveable, I use
https://github.com/umano/AndroidSlidingUpPanel/
library and when I set WebView on the bottom (slideable) part - it doesn't scroll. at all.
As I suppose - it is same as setting ListView on a ScrollView.
Is there anything possible to do or at least to try??
Well, As far as it's not an everyday issue, but still important for those who use this wonderful Library, here's the answer to use ListViews,GridViews, WebViews and everything that may scroll on the second, hidden child.
First - you need to use method setDragView(view) to define which view will be used for dragging
Second - second child if it's Layout (which is most likely" should be set as android:clickable="true" in layout.xml
And here you are - you can scroll second child's Views too.
It's not an often issue but it was really hard to find some info in the internet
Related
export default class Video extends Component {
render() {
return (
<ScrollView style={styles.container}>
<ImageBackground source={require('../asset/Video-Img.jpg')}
style={styles.bgImg}>
<MaterialIcon name="play-circle-outline" size={55} color={'#fff'} />
</ImageBackground>
This is how i execute my code instead of Container View. Any problem will happen with this?
Just a suggestion but if developing for iOS, I would wrap the entire ScrollView within SafeAreaView.
<SafeAreaView>
<ScrollView style={styles.container}>
<ImageBackground source={require('../asset/Video-Img.jpg')}
style={styles.bgImg}>
<MaterialIcon name="play-circle-outline" size={55} color=
{'#fff'} />
</ImageBackground>
</ScrollView>
</SafeAreaView>
Why?
The purpose of SafeAreaView is to render content within the safe area
boundaries of a device. It is currently only applicable to iOS devices
with iOS version 11 or later.
But ScrollView as you have is perfectly fine to do so. Just be sure to read up on the documentation - especially the part in the first paragraph relating to the height.
Also, depending on how much content you are displaying - it may have an impact on performance.
ScrollView renders all its react child components at once, but this
has a performance downside.
If you are looking to just list items, consider FlatList.
This is where FlatList comes into play. FlatList renders items lazily,
when they are about to appear, and removes items that scroll way off
screen to save memory and processing time.
FlatList is also handy if you want to render separators between your
items, multiple columns, infinite scroll loading, or any number of
other features it supports out of the box.
Yes you can use scrollview instead of view
I would like to implement the following behavior in an android application:
So should I use fragments with horizontal ScrollView, a ViewPager or what exactly? Would it be better to use CardView?
And how to add the 2 dots at the bottom to show that we still have for example another page to show?
Finally, I need only one fragment/CardView to be present at a time. That is, I don't want to see half of the first fragment and half the second. That would be annoying.
I would like to know in general what pieces to use for this purpose.
Any help is much appreciated!!
I would use ViewPager. It will give you all of the functionality you're looking for and will allow you to add or remove pages easily in the future.
You will have to manually create a page indicator (the dots at the bottom) or use a library like this:
https://github.com/romandanylyk/PageIndicatorView
I have a ScrollView which contains several RelativeLayouts and LinearLayouts like this:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<RelativeLayout >
</RelativeLayout>
<LinearLayout >
</LinearLayout>
</ScrollView>
Now, when I click on one of those layouts, I want it to expand and reveal more information. I have managed to do this by scaling the layout I want vertically with a PropertyAnimator:
relativeLayout.animate().scaleY(100).setDuration(duration).start();
At the same time, I use another PropertyAnimator to move any Views below the one I expanded vertically so that there's enough space for the expanded layout. So far it is working.
Unfortunately, the Views that move somehow end up outside of the viewport of the ScrollView, so I'm unable to scroll down and see the information in those Views. Essentially, the vertical translation of those views renders their lower part unreachable, since the viewport does not expand too.
I have set android:fillViewPort="true" on the ScrollView. And I have also tried to do it programmatically with setFillViewPort() but neither has had any effect.
What's wrong? Why is it not working?
When you perform translation animations on Views then those Views don't really move inside the layout. Its just visual for the User, but when it comes to layouting and/or measuring than any translation values are ignored. It is always as if the Views are not translated at all.
What I am guessing you are doing right now is this:
You react to the click event and expand the View you want to expand.
You calculate how much the other Views need to move to accommodate the expanded View.
Then you perform translate animations on those Views by much they need to move.
And then as a result suddenly a few Views move off screen.
This approach can actually never work. You always need to remember that a Views position in the layout is determined just by the layout. All your translations are essentially just for show. So this is what's actually happening when you try to do the above:
You react the to the click event and expand the View.
This expansion causes Android to start a layouting and measuring process. The positions and sizes of all Views is calculated and they are positioned at their new location with their new size.
Since now the Views are already at the location they are going to be after the expansion you translation animation just moves the Views further down, beyond the point they are supposed to be.
As a side effect of this the Views seem to move off screen for no apparent reason.
So what can you do about this? Essentially you need to tackle this problem the other way around. As I mentioned above Android already calculates the new sizes and positions of all Views for you, and you can use that to your advantage.
There are two basic solutions for your problem. Either you let Android perform the animations for you with LayoutTransitions or you perform your animations manually. Both ways use something called the ViewTreeObserver. It can be used to listen for changes in the layout or new drawing processes.
But first and foremost: ScrollView is supposed to work with only one child. So to prevent any future bugs or problems put all your items in the ScrollView inside of another LinearLayout with vertical orientation.
1) Using LayoutTransition
This would only work from API Level 16 and above. Below API Level 16 visibility animations and translation animations would be handled automatically, but to get height changes animated you need to have API level 16.
One important thing I have to mention is that:
LayoutTransition animates changes for you. So you can remove all you custom animations if you use it. If you leave your own animations in you are just going to create conflicts with the animations performed by LayoutTransition.
If you don't like the animations performed by LayoutTransition you can customise them! I will explain how to do that further down below.
I usually use a helper method like this to setup a LayoutTransition.
public static void animateLayoutChanges(ViewGroup container) {
final LayoutTransition transition = new LayoutTransition();
transition.setDuration(300);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
transition.enableTransitionType(LayoutTransition.CHANGING);
transition.enableTransitionType(LayoutTransition.APPEARING);
transition.enableTransitionType(LayoutTransition.CHANGE_APPEARING);
transition.enableTransitionType(LayoutTransition.DISAPPEARING);
transition.enableTransitionType(LayoutTransition.CHANGE_DISAPPEARING);
}
container.setLayoutTransition(transition);
}
This will enable all possible automatic transitions on API Level 16 and above and just use the by default enabled transitions below that. Just use it like this:
AnimatorUtils.animateLayoutChanges(linearLayout);
If you call this method on the LinearLayout in your ScrollView then all changes to height/width/visibility of the LinearLayout and its direct children will be animated for you. Also item add/remove animations are taken care of for you.
To enable all kinds of transitions like resize animations you need to set the LayoutTransitions in code, but you can enable basic transitions like item add/remove animations by setting the property
android:animateLayoutChanges="true"
on a ViewGroup in your xml layout.
There exists only minimal documentation on LayoutTransitions, but the basics are covered here.
If you want you can customise the animations for each event like adding/removing a View or changing something about the View like this:
// APPEARING handles items being added to the ViewGroup
transition.setAnimator(LayoutTransition.APPEARING, someAnimator);
// CHANGING handles among other things height or width changes of items in the ViewGroup
transition.setAnimator(LayoutTransition.CHANGING, someOtherAnimator);
Here is a DevByte video which explains LayoutTransitions in greater detail:
LayoutTransitions enable easy fade/move/resize animations
Also note that container views can essentially cut off parts of the animations when the height of a parent changes. This won't happen in your case since your ScrollView has a fixed size and does not resize based on the children inside the ScrollView, but if you implement something like this in a ViewGroup with wrap_content then you need to set android:clipChildren="false" on all containers above the Views you are trying to animate. You can alternatively also use setClipChildren() in code.
2) Animating all items manually.
This is a much more difficult than using LayoutTransitions, mainly because you have to know a lot about the layouting and measuring process, otherwise you are going to cause problems. Nevertheless once you get the hang of it you can perform all kinds of custom animations.
The basic process is like this:
Record current View state.
Change layout to the state after the animations are finished
After Android is done layouting and measuring everything record the new values.
Now animate the Views from their old position to their new one
The core of this process is listening for changes in the view hierarchy. This is done using the ViewTreeObserver. There are multiple possible callbacks you can use, for example OnPreDrawListener or OnGlobalLayoutListener. Generally you would implement them like this:
final Animator animator = setupAnimator();
animator.setTarget(view);
// Record the current state
animator.setupStartValues();
modifyChildrenOfLinearLayout();
linearLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
// Remove the callback immediately we only need to catch it this one time.
linearLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
// Record the new state
animator.setupEndValues();
// Start the animation
animator.start();
}
});
OnGlobalLayoutListener is better at catching layout changes since it is called after a layouting process has finished. OnPreDrawListener is called before the next frame is drawn, but their is no guarantee that the layouting process has already finished. But in practice this difference is negligible. Much more important is that on older slower devices there might be a short flash of the layout in its new state because they need some time to process each step. You can prevent that by using an OnPreDrawListener and returning false once. Since OnGlobalLayoutListener is also only completely available on newer API levels you should in most cases use OnPreDrawListener.
If LayoutTransitions does not provide you with an adequate solution to your problem and you have/want to implement the animations manually than learning how to perform animations efficiently is important. You can look at the source code of LayoutTransition here. The implementation of LayoutTransition essentially does exactly what I have been explaining here and it is a best practice implementation. I often find myself looking through the source code of the android.animation package to learn new things about how to animate efficiently and if you want to understand animations on Android I suggest you do the same!
You can also watch a few Android DevBytes videos about animations like this one:
ListView Expanding Cells Animation
In this video he explains how to animate an expanding cell in ListView by using an OnPreDrawListener.
Just always remember, the Layouting Engine is your friend. Don't try to reinvent the wheel and do stuff manually a layouting process would already do for you. And never call requestLayout() while performing animations!
From Android Developer site :
A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.
I can see that you have added multiple layouts as child in Scroll View, please add one linear layout and add rest of layout in that LinearLayout.
Hope it will solve your problem
Try this.
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout >
</RelativeLayout>
<LinearLayout >
</LinearLayout>
</LinearLayout>
</ScrollView>
Scrollview must have only one child to it. So I created only one LinearLayout child and add your rest code in it.
just add android:clipChildren="false"to your parent animated view and animation works outside of view.
I have defined my Relative Layout using the drag and drop tool in Eclipse, so all of my buttons are laid out how I wish. My issue is when I set the onClick listener, that calls a method in another class. So to be able to redraw items on screen, I need to access the layout manager so I can add and remove buttons from the screen as well as update textViews. I have done all of this in a demo I made in Java, and I used a JPanel with GridBagConstraints. Now that I am moving to Android, a system I haven't done much development in, I am at the point where I have to learn some new stuff. For example in my demo I made I could do this:
grid.remove(trueButton);
grid.add(falseButton);
grid.remove(textField);
grid.add(backButton);
Essentially I want to be able to do the same sort of thing in my Android app. If you guys need more info I can provide, I wasn't really sure how much would be needed since I am looking at really just where to start. Everything has been declared in the XML since the drag and drop part of Eclipse does that all for me. It is just the Java part that is giving me some issue.
Why not just setVisibility of the buttons you wish to hide/show? Same with the TextViews.
You can set visibility to 'GONE' and it will be as if the view has been removed (taking up no space in the layout and not responding to touch events.).
I've been searching for this topic for a while, and can't find enough resources or tuts about scrolling a PagerTabStrip. I'm using the FragmentStatePagerAdapter and populates the PagerTabStrip with getPageTitle(int position). I'd like to know how to make the titles scrollable. I'd like to scroll the titles without affecting the view by the time I stop or select into a specific title, then that's the time the view gets updated. I've been thinking to use HorizontialListView but not sure how to start. Hoping to learn from you. Thanks.
Found this on docu:
PagerTabStrip is an interactive indicator of the current, next, and
previous pages of a ViewPager. It is intended to be used as a child
view of a ViewPager widget in your XML layout. Add it as a child of a
ViewPager in your layout file and set its android:layout_gravity to
TOP or BOTTOM to pin it to the top or bottom of the ViewPager. The
title from each page is supplied by the method getPageTitle(int) in
the adapter supplied to the ViewPager.
I been searching on this on the web, but I didn't get any relevant resources. I just found out another library called actionsherlock that enables the scrolling of tabs without affecting the view which is exactly what I need, instead of using PagerTabStrip's listener .
I'm also searching for the same thing. Too bad you have to make your own implementation or use third-party library. I have read that this library offer the feature of scrolling tab independent of the content. But I have not tried it out yet.
http://viewpagerindicator.com/?utm_source=androidweekly&utm_medium=toolbox
Do you actually mean the ActionBarSherlock? Do you have an example?