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;
}
});
Related
i'm using a Material swipe tab to show with swipe 3 different fragment layout.
This is the xml layout for swipe tab:
<LinearLayout 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"
tools:context=".MainActivity">
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<com.android4devs.slidingtab.SlidingTabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="2dp"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
></android.support.v4.view.ViewPager>
</LinearLayout>
Now the xml layout fragment of swipe have a button fixed into bottom of layout so when i swipe to this fragment the layout of fragment is cut see image:
there some way to fix the layout fragment into ViewPager or a way for scroll it with a scroller view?
Thanks
In your second Fragment, you can use
scrollView.post(new Runnable() {
#Override
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
To scroll your ScrollView to the bottom, so your Button will be totally visible.
I've got a problem with my view which looks like below:
My view before scrolling
My view after scrolling
As you can see it's supposed to be a scrollable view with unscrollable ListViews.
It consists of DrawerLayout inside which I've got CoordinatorLayout (with AppBarLayout and my FrameLayout containing my fragments) and NavigationView.
activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:background="#color/colorBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_vision"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_vision"
app:menu="#menu/activity_vision_drawer" />
app_bar_vision.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorBar"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways|snap"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"/>
Now the main part. My fragment layout consists of ScrollView inside which there is RelativeLayout inside wich I've got two ListViews wchich height is set programatically according to assigned elements.
fragment_preferences.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="#layout/content_preferences" />
</ScrollView>
content_preferences.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:layout_gravity="center_horizontal"
tools:context="dron.mkapiczynski.pl.dronvision.fragment.PreferencesFragment"
tools:showIn="#layout/fragment_preferences">>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Preferencje wizualizacji"
android:id="#+id/preferencesTitle"
android:layout_gravity="center" />
<TextView
android:id="#+id/trackedListTitle"
android:text="Drony śledzone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/preferencesTitle"
android:layout_marginTop="20dp"/>
<ListView
android:id="#+id/trackedDroneList"
android:layout_below="#+id/trackedListTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:layout_centerInParent="true"
tools:showIn="#layout/fragment_preferences"/>
<TextView
android:id="#+id/visualizedListTitle"
android:text="Drony do wizualizacji obszaru przeszukanego"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/trackedDroneList"
android:layout_marginTop="20dp"/>
<ListView
android:id="#+id/visualizedDroneList"
android:layout_below="#+id/visualizedListTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:layout_centerInParent="true"
android:nestedScrollingEnabled="true"
tools:showIn="#layout/fragment_preferences"/>
In general scrolling works but only if I touch the screen in areas outside of ListView for example in area with my TextView. When I try to scroll in areas with ListView nothing happens.
I'll be gratefull for any advice. I've tried to implement my own nonScrollingListView extending ListView thought that may enable parent scrolling but that doesn't help.
I've also read about using LinearLayout instead of ListView but maybe there is still a way to use ListView with ScrollView?
It is generally a discouraged to use a Scrollable view as a childview of the scrollview or any other scrollable content.
But, however if there is a need of the application and if the developer wants to handle the scrolling events smoothly, below is the way to handle the scrollable contents individually,
For the parent scrollview, you can handle the scrolling event as
m_parentScrollView.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View p_v, MotionEvent p_event)
{
m_childScrollView.getParent().requestDisallowInterceptTouchEvent(false);
// We will have to follow above for all scrollable contents
return false;
}
});
For the child scrollview,in your case Listview, we have to handle the event as shown below:
m_childScrollView.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View p_v, MotionEvent p_event)
{
// this will disallow the touch request for parent scroll on touch of child view
p_v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
You can get more details about it from here:
handle-scrollable-views-or-controls-in-another-scrollview-in-android
Also, as a side note, I have also faced some similar issues while using Scrollview and RelativeLayout and this user is also facing same issue as you.
Hope it helps you :)
There is a viewpager and a RelativeLayout in a relative layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:weather="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mainview_id">
<android.support.v4.view.ViewPager
android:id="#+id/main_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<PushPullDoorView
android:id="#+id/pull_down_view"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</PushPullDoorView>
the PushPullDoorView have been override the onTouchEvent method.it can be dragged down and up.But when I try to move the viewpager,it does not response the event.I try to override the dispatchTouchEvent,onInterceptTouchEvent,and set the return value of true or false.It still does not work.
Both PushPullDoorView and android.support.v4.view.ViewPager are having android:layout_height="match_parent" so only one view will be in contact in the screen. Try to change the layout design to resolve this.
I have a RecyclerView in a LinearLayout. How can I have LinearLayout "slide" upwards until it hits the App Bar, whereby the RecyclerView should then begin scrolling the items as usual. Likewise, scrolling the list down will begin to "slide" the entire container down when the the first item is reached in the list until the container returns to its starting position.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/nearby_stops"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="#dimen/half_padding"
android:paddingTop="#dimen/half_padding"
android:scrollbars="none" />
</LinearLayout>
I looked at https://github.com/umano/AndroidSlidingUpPanel, however it does not support RecyclerView and the moment.
Put the RecyclerView inside a Fragment, so make an XML like so for the Fragment:
This is your XML for the RecyclerView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/nearby_stops"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="#dimen/half_padding"
android:paddingTop="#dimen/half_padding"
android:scrollbars="none" />
</LinearLayout>
Then for the Activity hosting the Fragment just add a FrameLayout for the Fragment:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Put other views here -->
<FrameLayout
android:id="#+id/slidingFragmentContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Then inside your Activity when you instantiate the Fragment do the following:
SampleFragment listFragment = new SampleFragment();
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom,
R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom)
.addToBackStack(null)
.add(R.id.slidingFragmentContent, listFragment)
.commit();
The animations R.anim.abc_slide_in_bottom and R.anim.abc_slide_out_bottom are available in the Android API.
I also noticed you're not setting any orientation for your LinearLayouts. Set an orientation like so android:orientation="..."
You can assign a Button to show the Fragment, like so:
mButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
showFragment();
}
});
--------------------------------------------------------------------
To get the RecyclerView to scroll up as you scroll it just use the following:
Create an XML layout like this for your Activity:
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="#dimen/map_view_height"
android:orientation="vertical"
android:fitsSystemWindows="true">>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<YourCustomViewContainingTheMap
app:layout_collapseMode="parallax"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
Inflate your Fragment inside the FrameLayout and then as you scroll up it should do a parallax animation on the Map. If you don't want a Parallax effect just set app:layout_CollapseMode="pin"
Here is a sample app I created, you can see as I scroll up on the RecyclerView it slides up:
(Please note the Frame Animations on GIFs is not that great)
To get a shadow behind the sliding list on your map, just set app:layout_collapseMode to parallax and then add another view in front of your MapView inside the CollapsingToolbarLayout which can be your mask, it can be be a simple view, and then you can adjust it's alpha value as you scroll up the list.
It's better to use the native android views at your disposal, I noticed that AndroidSlidingPanelLayout has around 43 issues.
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.