I have an activity that has a LinearLayout which in turn is split in three more LinearLayouts .
I want to make the top-third horizontally 'swipable'. The solution I assume to make a view swipable is to implement ViewPagers. I am not able to figure out how to get a ViewPager inside a LinearLayout. Also I would rather NOT have tabs on top of each view inside ViewPager.
My solution will be to use a ViewFlipper:
<LinearLayout ... >
<ViewFlipper>
<RelativeLayout>
<!-- your design here (part1)-->
</Relativelayout>
<RelativeLayout (redifine with same id)>
<!-- your design (part2)-->
</RelativeLayout>
<!--repeat for further parts of your design-->
</ViewFlipper>
</LinearLayout>
I am not able to figure out how to get a ViewPager inside a LinearLayout
Same way you get anythign else into a LinearLayout.
<LinearLayout ... >
<android.support.v4.view.ViewPager ... />
<!-- other children -->
</LinearLayout>
It won't have tabs on top since those are not part of ViewPager itself. I recommend spending time looking at the ViewPager docs.
Related
I have one Android application(Xamarin.Android) and it has many fragments.
All fragments have the link to website in bottom.
Ideally I'd like to create it as custom fragment with link to website and add to all fragments.
But I don't find any way to add this fragment to XML of every fragment without coding.
I don't want to add the custom fragment to FrameLayout of other fragments in code.
Please let me know if anyone knows best solution for this kind of footer.
Thanks.
You can add the footer to the activity and use fragments for other screens. (Fragment frame layout above the footer in the main activity obviously)
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/footer">
</FrameLayout>
<FrameLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="center"
android:text="Footer content"/>
</FrameLayout>
You can make a custom layout with your footer view at the bottom of the view and extend it for all your parent layouts.
Here is the simple way that I found.
Create new XML layout for footer
Create custom fragment class for this footer
Add this footer fragment to end of layout as needed as following
That's all!
I have a layout in my head that should look like that: http://i.imgur.com/H1nTRvd.png
Only part that will be dynamic is the blue one. I don't know the number of tabs that will be created before I load the activity, hence the number is acquired from server (could be either 5 or 24 for all I know).
The bottom buttons should not move when I swipe and the blue area changed.
Currently I have this implemented w/o tabs list using embedded fragment in my activity and gesture listener. There's no good looking transaction animation between fragments.
#Nick Pakhomov: You can use PagerTabStrip
PagerTabStrip
is intended to be used as a child view of a ViewPager widget in your XML layout. PagerTabStrip is most often used with fragment, which is a convenient way to supply and manage the Lifecycle of each fragment.
So here’s how a ViewPager with a PagerTabStrip in it would look like in the layout file:
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTabStrip
android:id="#+id/pager_tab_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:textColor="#fff"
/>
</android.support.v4.view.ViewPager>
Please check this PagerSlidingTabStrip demo . I hope it will helps you .
I want to add scrollable tab in an xml file. Normally I can add it like
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.scrollabletab.MainActivity" />
and it looks like:
but now I want to add this scroll tab at center of view. Center means above this scroll tab I have app logo, some layout which contains different textviews. and also I want to add some layout below this scroll tabs which again contains different textview and layout.
How to do this?
You can try this one widget: http://viewpagerindicator.com/
But common answer is: use Actionbar with Tabs:
http://developer.android.com/guide/topics/ui/actionbar.html#Tabs
Why don't you use a ScrollView within the layout that you use for your pager?
i was just wondering if it was possible to have in one layout xml file, maybe a vertical linear layout at the top have a horizontal linearLayout and then below that (inside of the vertical layout) have a list view that takes up the rest of the screen?
I couldnt find any information specifically on this, and i'd like to know if its possible before i attempt it, thanks!
Give the ListView layout_height="0dp" and layout_weight="1". It will take up the remaining space not used buy the sibling LinearLayout.
<LinearLayout
android:layout_width:match_parent
android:layout_height:match_parent
android:orientation:vertical >
<LinearLayout
android:layout_width:match_parent
android:layout_height:wrap_content
android:orientation:norizontal >
<!-- other views --->
</LinearLayout>
<ListView
android:layout_width:match_parent
android:layout_height:0dp
android:layout_weight:1 />
</LinearLayout>
I'm running into trouble when try to put an tabhost layout inside an normal layout.
The structure of my layout is:
<LinearLayout >
<LinearLayout>
....
</LinearLayout>
<TabHost>
.....
</TabHost>
</LinearLayout>
I try to draw this picture to help it easier to image about what I'm saying:
Can you give me a hint for this problem ? I will do the rest, no need a full solution, just a hint, please :)
Thanks .
It's been a little while since I dealt with Android, but if I recall TabHost is essentially a container that stores both the tabs and the viewport that the tabs switch between. TabHost extends from FrameLayout so you can use it as the root element in a layout. What I think you actually want is this:
<TabHost>
<LinearLayout android:layout_orientation="vertical">
<TextView /> // your title
<View /> // content below your title but above your tabs
<TabWidget /> // your tabs
<FrameLayout /> // content controlled by your tabs
</LinearLayout>
</TabHost>