View Pager and Gridview wrap_content - java

I have custom view with extends LinearLayout. Custom view is viewpager with grid view inside. I add "wrap_content" wherever possible, but my view spend whole screen or only one grid's view line.
I find examples GridView with wrap_content function, but it is not help me

Related

Programmatically add visible views to Android textureview

I want to know if it's possible to programmatically add a view to the texture view (camera2).
If I add the texture view to a frame layout which has a view in it, then that view is not visible.

Use RecyclerView and ViewPager in CoordinatorLayout

I have a layout, I need to use recyclerView and TabLayout and ViewPager in the last item in CoordinatorLayout.
but just recyclerView scroll and show, TabLayout and ViewPager don't show.
anybody can help me?
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<Layout/>
<Toolbar/>
</CollapsingToolbarLayout>
<TabLayout/>
</AppBarLayout>
<ReyclerView/>
<TabLayout/>
<ViewPager/>
</CoordinatorLayout>
What's the size of the RecyclerView? Is it MATCH_PARENT? Try setting a smaller height to recyclerView and check whether the viewPager is visible. You need to enclose all three views inside scrollView and make recyclerView, a nested scroll.

Combine Vertical scoll view of parent layout and contents of view pager

I have a 'page' that has a number of components on it, and who's content is longer than the height of the device. one of the component is view pager. Content of view pager is also very large. How can i combine vertical scroll view of parent layout and view pager layout.My laytout is as follows:
few components
view pager-(large content in another layout)
few more component
i want to combine scroll view of view pager and parent layout
It should just work. See here -> ViewPager inside a ScrollView does not scroll correclty
You structure should be like this:
ScrollView
-ViewPager
--ScrollView
Then just apply the suggestions made in the linked post above.
Also make sure the ViewPager has a fixed height! Otherwise the ScrollView inside the ViewPager won't work without writing a custom ScrollView or ViewPager.

Android: Prepend LinearLayout programmatically

I created a layout in my application that includes the followings:
main_layout (FrameLayout, fills whole screen)
-> includes: main_interface (LinearLayout, height/width fills parent)
Now I want to add another LinearLayout in the main_layout BEFORE the main_interface.
I tried this:
LinearLayout bar = new LinearLayout(this);
bar.setGravity(Gravity.TOP);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
bar.setLayoutParams(params);
main_layout.addView(bar);
but this just overlaps my main_interface.
Any Help?
If you want to add a View to specific position in a ViewGroup, you can use addView(view, position). In this case, assuming main_interface is the first View, you can call main_layout.addView(bar, 0).
However, you need to fix your layout first. If you use FrameLayout as your main_layout and set main_interface height and width to match_parent, then they will surely overlap. Try making your main_layout a LinearLayout with android:orientation="vertical" if you want vertically stacked Views.
If you could post your actual XML layout, I could help you modify and test it.

Off set android view while using android:layout_centerVertical="true"?

I'm trying to get a view center vertically in android, but I have a imageView at the top that is 75dps, so I need my centered view to be offset from the top by 75dps so it gets centered! Is there a way to do this? I tried using android:layout_marginTop="75dp" but it didn't work! Any ideas?
You could wrap your view into a ViewGroup (e.g. LinearLayout), then make the LinearLayout centered, and add the marginTop to your view. It should work.
Anyway, it would be helpful if you post also your layout xml.

Categories