View Pager not scrolling vertically android? - android

I have ViewPager with ListView below it in Linear Layout. Its working fine however when I am try to scroll only ListView scrolls while ViewPager remains static.
This is my XML code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="150dp"
android:isScrollContainer="true" />
<ListView
android:id="#+id/categorylist"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
I want ViewPager also to scroll and move upward rather than remaining static.

#vo12 Add View pager as the header of the list.
And for the error that you are getting.
Remove view pager from that xml:
<ListView
android:id="#+id/categorylist"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
. Create a new View pager in code or inflate a different xml.
<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="150dp"
android:isScrollContainer="true" />
And add the header view
View headerView = getLayoutInflater().inflate(R.layout.header_view , null , false);
listView.addHeaderView(headerView);
You were getting an error because your viewpager was attached to LinearLayout and so it's layoutparams were set accordingly but to add it to the list you either need to remove this view from linearlayout and add or add a new one.

Try to add the ViewPager as a header of your listview.

Related

Scrolling in View Pager

I have an activity in which I have taken single tab layout and content of this tab layout is contained inside a viewpager.
This is my part of the code of main activity containing the tab layout and the viewpager.
<android.support.design.widget.TabLayout
android:id="#+id/materialup.tabs"
android:layout_width="fill_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/selecteditem"
android:fillViewport="true"
app:tabBackground="#drawable/tab_background"
app:tabGravity="fill"
app:tabIndicatorColor="#0000"
app:tabIndicatorHeight="4dp"
app:tabMode="fixed"
app:tabSelectedTextColor="?android:attr/textColorPrimaryInverse"
app:tabTextColor="#color/white" />
​
<!-- The top margin value equals half height of the blue box -->
<android.support.v4.view.ViewPager
android:id="#+id/materialup.viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
and for the content of this viewpager I have taken a Fragment class which contains a expandable list view, here is the part of code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="4dip"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frstll"
android:orientation="vertical">
<ExpandableListView //list view taken for list items
android:id="#+id/expandableListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ffffff"
android:childDivider="#f4f4f4"
android:dividerHeight="1dp"
android:groupIndicator="#null" />
</LinearLayout>
</LinearLayout>
The problem is that when I touch on the tab(the green portion in the image), the layout scrolls perfectly but when I click on the expandable listview's part (the portion with white background in the image) it does not scroll.
So how can I achieve scrolling by touching on the expandable list part?
This is the layout I have acheived using the above code.
I want to know why the default scrolling feature of expandable listview is not working here in my code.
Should I change my Main Activity's layout or a minor change in the expandable listview's code in my fragment class?
Please add touchlistener on ExpandableListView
yourRecyclerview.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});

SwipeRefreshLayout not allowing listview row item horizontal scrolling

I have viewPager inside that there is 2 Fragment. Inside fragment1.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_color"
android:focusable="false"> <android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listView_feed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animationCache="true"
android:clipToPadding="false"
android:divider="#color/transparent"
android:dividerHeight="2dp"
android:paddingBottom="12dp"
android:paddingTop="12dp"
android:scrollbars="none"
android:focusable="true"
android:scrollingCache="false"
android:smoothScrollbar="true" /></android.support.v4.widget.SwipeRefreshLayout></RelativeLayout>
And in listView_feed there is another horizontal_listview inside listView_feed each row but while adding inside SwipeRefreshLayout it will not allowing horizontal_listview horizontal scroll and focus moved to pager. But if I move listView_feed outside SwipeRefreshLayout then each listView_feed child can scroll horizontally.
Thank you who tried and see my question. Finally I found one good library by using it I was able to achieve my requirement. But it is not same as SwipeRefershLayout. It is refreshing in header not over Listview but it works great.

How to make the last footer fixed (ListView)

I have a ListView with 2 footer views. The first one is a bunch of TextViews, while the second one is a button. I'm trying to fix the second footer so that it always shows at the bottom of the screen.
I tried the following:
1. alignParentBottom = true
2. layout_gravity="bottom"
3. footerView2.bringToFront()
And combinations of the above. But none of them worked out. How can I achieve this?
UPDATE
I shouldn't have added the View which I always want on the screen (fixed) as footer.
I just added the wannabe-fixed-view with the listView. Did alignParentBottom = true and also view.bringToFront(). It worked out for me.
Separate your ListView and bottom footer. The idea is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/btn_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Bottom button"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/btn_bottom"/>
</RelativeLayout>
Create separate xml file which contain all textviews and button you want as footer part.Then bind this xml as a footer of listview. You can binf footer with listview by this method: listview.addFooterView(footerView);
For example:
View footerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.listviewfooter, null, false);
spDate = (Spinner) headerView.findViewById(R.id.spdate);
llDatepicker = (LinearLayout) headerView.findViewById(R.id.lldatepicker);
rvDatepicker = (RecyclerView) headerView.findViewById(R.id.rvdatepicker);
rvTimepicker = (RecyclerView) headerView.findViewById(R.id.rvtimepicker);
lvAddress.addFooterView(footerView);
If you are Trying to add a View which will be shown even if we scroll the List Up or Down... u can do something like this. I had done this before But as a header.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/new_container"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LOAD EARLIER MESSAGES"
android:id="#+id/loadMore"
android:background="#90F58220"
android:visibility="visible"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listContainer"
android:layout_below="#+id/loadMore"
android:layout_above="#+id/container">
<ListView
android:id="#+id/messagesContainer"
android:transcriptMode="normal"
android:dividerHeight="0dp"
android:divider="#null"
android:stackFromBottom="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/container"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:background="#ffffff"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:layout_height="wrap_content" >
</RelativeLayout>
The LoadMore Button is always visible on the Top of the List...
To add it to footer, Just Change
android:layout_below="#+id/loadMore"
android:layout_above="#+id/container"
to
android:layout_above="#+id/loadMore"

Translating view and viewpager's fragments

I have a little strange problem for me. I need to translate view which is located over a viewpager on recyclerview scroll. RecyclerView is located in fragment and fragments are located in viewpager. When I scroll recyclerview in fragment and want to translate View which is located over viewpager my problem occurs. ViewPager is moving up to fill space left by translated view, but fragments aren't. Because of it I can see space empty space on viewpager. I checked it by setting viewpager background and i saw that viewpager actually resized to match container but fragments remained still. Any ideas how to force it to works as it should be? This code works perfectly when recyclerview and view which I want to resize are on same fragment.
Issue look like this http://i.imgur.com/wyxXGYh.png
Layout look like this
ViewPagerFragment
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:clipToPadding="false">
<android.support.v7.widget.RecyclerView
android:id="#+id/subcategory_fragment_recycle_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
Layout with Viewpager
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/fragment_category_sliding_tab_layout">
<android.support.v4.view.ViewPager
android:id="#+id/fragment_category_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="100dp"
android:clipToPadding="false"
android:background="#0000FF"
android:animateLayoutChanges="true">
</android.support.v4.view.ViewPager>
<TextView
android:id="#+id/scrollTemp"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#FF0000"
android:gravity="center|center_vertical"
android:text="TEMP"
android:textSize="40dp" />
</FrameLayout>
For detecting scrollevents and triggering show/hide of temp view I am using basically this HidingScrollListener https://mzgreen.github.io/2015/02/28/How-to-hideshow-Toolbar-when-list-is-scrolling%28part2%29/. As I said it works perfectly when recyclerview and view which I want to scroll are on same fragment.

ListView with custom adapter and other view elements

I am learning to use the Hierarch Viewer tool, but meanwhile any hint on why below layout is not rendering correctly is appreciated.
I am trying to render an "html" table view. The content (table body) is rendered correctly with a custom list adapter. This works. But, when I add a textView (text_test below) to use as header, the list is not rendered anymore. I could see the code flow through my adapter (populate view holder, etc), but on screen I only see the Title text, no listView. I used to use FrameLayout (as noted in the comment), but then switched to LinearLayout.
Thanks.
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.my_list_view, container,
false);
ListView lv = (ListView)view.findViewById(R.id.my_list_view_one);
// Tell the list view which view to display when the list is empty
//lv.setEmptyView(getActivity().findViewById(R.id.my_list_view_empty));
// Set up the adapter
mCustomAdapter = new ListAdapterMyType(inflater, new ArrayList<MyType>());
lv.setAdapter(mCustomAdapter);
return view;
}
my_list_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The frame layout is here since we will be showing either
the empty view or the list view. -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/text_test"/>
<ListView
android:id="#+id/my_list_view_one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"/>
<!-- Here is the view to show if the list is emtpy -->
<TextView android:id="#+id/my_list_view_empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/list_no_items"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
But, when I add a textView (text_test below) to use as header, the list is not rendered anymore.
The TextView is set to match_parent in both the width and height, so it will fill the entire screen... To put a TextView above your ListView try:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/text_test"/>
<ListView
android:id="#+id/my_list_view_one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"/>
<!-- Here is the view to show if the list is emtpy -->
<TextView android:id="#+id/my_list_view_empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/list_no_items"
android:visibility="gone"/>
</LinearLayout>
I removed the outer LinearLayout, since it only had one child it did nothing. I also changed the remaining LinearLayout's orientation to vertical and set the header TextView height to wrap_content.
If you want your custom header to scroll with your ListView, use the addHeaderView() method (before calling setAdapter()) instead of a separate TextView in your layout. This approach will also hide the header when the ListView is empty.

Categories

Resources