I am having a really weird problem. Here it goes:
I have got a viewpager which I use to navigate between some fragments. In one of those Fragments I am adding a surfaceview that is supposed to fill the whole UI to a relativelayout. I add it like this:
mRelativeLayout.addView(mMySurfaceView);
Now, the problem is that even though the surfaceview fills up the whole screen, the viewpager does not. There is a small gap between viewpager and screen border. In other words, the viewpager does not fill up the whole width.
However, when I add another ui element to my relativelayout, like an imagebutton like this:
mRelativeLayout.addView(myImageButton);
then everything is fine and the viewpager fills up the whole screen.
Why is this happening??
Try with:
//in onMesure()
mMySurfaceView.setMeasuredDimension(int, int)
more info: http://developer.android.com/reference/android/view/View.html#onMeasure(int,int)
Related
I am making an application to change the image after applying some effects on it. The image is at the main screen, and on the same screen,there is a framelayout containing several recyclerviews. I want to click an item in recyclerview so imageview changes.
Before using navigationview (framelayout) I only had recyclerview, from which I could manage the ImageView perfectly (from onBind.... function). However, since I wanted it to be in a frame to be able to change to other buttons, I moved the code to other Class, so when I do findviewbyid, i get null so I cannot do any work.
I have been searching a lot and trying many things but still I dont have any clue.
Someone has got any idea?
I saw beatport's app intro with viewpager, and what I want is to create that effect on scroll, for example, when changing to the next fragment, the background image of the fragment before adjust itself in the center of the remaining space.
Maybe I wasn't very specific, I'll be glad if you could take a look at beatport's app Intro for more understanding. The effect is called Parallax and I found this pieces of code, but I canĀ“t implement my fragments, only the images.
Here is the code:
https://github.com/je4a/ParallaxViewPager/tree/master/sample/src/main/java/com/parallaxviewpager/sample
I'm having trouble aligning the fragments to the center of the view pages, in a way that the user can see multiple fragments on the screen. This problem has already been solved before, but not when the fragments have different size.
Can ViewPager have multiple views in per page? is one link that I used. The pagercontainer solution on it works but is very slow. My solution was to set ViewPager padding through setPadding(int, int, int, int) method and false for setClipToPadding. Doing so makes the fragments look as if they're aligned in the center, but assumes that all fragments are the same size (since setPadding is a global setting for a View). So having different fragment sizes just completely messes the alignment.
I was hoping if someone knew how to make it so that the current fragment in view pager can be aligned to center without the use of padding. That way one could have different fragment sizes. Alternatively, could someone suggest how to achieve center alignment with padding with variable fragment sizes?
PS: I've searched everywhere online and couldn't find a solution.
Rather than aligning the fragment inside the viewPager, why dont you try putting all your elements in a layout and then align it to center(inside the fragment).
Make viewPager as wrap_content. and make fragment main layout params as wrap_content too.
If this does not help you. You can share your layout.Also, add one more tag to your question - "android_layout"
The TabCarouselLibDemo source is here. Thanks for the author's work.
The demo shows the ViewPager is below the tab, but in the xml, the ViewPager seems that it is at the top of the tab.
I think if you can see the demo you will understand what I mean.
I have a question about how to make the ViewPager below the tab? I have seen nothing about it in the code.
It makes me feel uncertain.
Thank you in advance!
It has to do with how RelativeLayout draws its children. If the ViewGroup was a LinearLayout and the orientation was set to "vertical", the carousel would be placed below the ViewPager, like you're thinking. But that's not how RelativeLayout works.
As far as the content in the ViewPager being below the carousel, you have to look at the custom Adapter used. There's a layout called "faux_carousel" that's used to create a layout with the same dimensions as the actual carousel, without showing the carousel itself. That layout is placed at position "0" in the Adapter so that all of the other content (that's in the ViewPager) will rest below the fake carousel and therefore the real one too.
My UI Layout is like this;
My question is, when the screen has enough space for FrameLayout's ListFragment's Fragment,
the ListFragment will be fully displayed. but if the screen is too small, ListFragment will be automatically compressed and cannot be fully displayed their contents.
I look forward to the effect is that if the screen is too small, scroll bars will appear, rather than changing the height of ListFragment.
Using the response of S.D, I have had the same problem with the ScrollView and ListFragment, the list always has the same height despite it is forced on the layout. Leaving the FrameLayout out of the ScrollView this problem disappears.
In your case, could be a good idea make your View a custom ListView where each item will be different. First item could be the first TextBox, the second item will be the first Fragment, and so on.
I hope that this response be helpful to you.