I have two recycler view inside bottomsheet, one is horizontal and other one is vertical.
I am able to scroll horizontally but not able to scroll vertically in second recycler view.
Is there any way to do vertical scroll?
This is work for me use NestedScrollview in xml
Like that
<android.support.v4.widget.NestedScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recyclerViewFeaturedLoc"
android:layout_below="#+id/recyclerViewHorizontal"
android:paddingTop="#dimen/activity_vertical_margin"
/>
<ProgressBar
android:layout_centerInParent="true"
android:id="#+id/home_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Then set vertical scroll view in java file
like that
recyclerViewFeaturedLoc.setNestedScrollingEnabled(false);
Related
I try to set my LinearLayout starts from screen edge(like Parent layout).I dont want the White Space between two layouts.
i need to start from left side from screen edge and top also edge . or follow the parent left and top properties.
NOTE:
suppose i dont want to change the Relative layout properties only changes in linear layout means how to fix it?
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.zd.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/preview"
android:focusable="true">
<requestFocus />
</LinearLayout>
</RelativeLayout>
DO LIKE BELOW.
<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"
tools:context="com.example.zd.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/preview"
android:focusable="true">
<requestFocus />
</LinearLayout>
</RelativeLayout>
remove these lines.. these are creating padding for the child.
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
But according your question.
<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/gray"
android:clipToPadding="false" // this will do the trick here
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
// suppose you have 16dp padding
<LinearLayout
android:layout_marginTop="-16dp"
android:layout_marginBottom="-16dp"
android:layout_marginLeft="-16dp"
android:layout_marginRight="-16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="#+id/preview"
android:background="#color/green"
android:focusable="true">
<requestFocus />
</LinearLayout>
</RelativeLayout>
I'm having issue with rendering a scroll view, below which I want a list view.
I want a scroll view, inside which I will add image views and text views or may be other UI elements.
Below this scroll view, I want a list view.
But when I do this, either the list view and scroll view overlap, or only the scroll view is rendered.
XML Code: Gist
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.dell.finalstartup.MainActivity"
tools:showIn="#layout/app_bar_main">
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<!-- For pic of the day -->
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/layout_PicOfTheDay"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pic of the day example layout"
android:textSize="22sp" />
<ImageView
android:id="#+id/picOfTheDay"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- Grey Line -->
<View
android:layout_width="match_parent"
android:layout_height="#dimen/gray_line_width"
android:background="#c0c0c0" />
</LinearLayout>
</ScrollView>
<!-- For products -->
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/scrollView" />
</RelativeLayout>
Its always an issue to have multiple scroll based views in the same layout. You can use a nested scrollview which is part of the V4 library.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.v4.widget.NestedScrollView>
For more on layout_behaviour and nested scroll.
Change the Relative layout to Linear layout will solve this issue..!!
I have layout with RecyclerView scrolling horizontally and gridview vertically.
but recyclerview dosen't scroll up in activity, leaving gridview scrolling vertically below horizontal recyclerview list.
i want recyclerview to be scrolled horizontally while whole layout vertically scrolling.
content_main.xml
<LinearLayout 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="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.test.MainActivity"
tools:showIn="#layout/app_bar_dash_board"
android:orientation="vertical"
android:scrollbars="vertical">
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:scrollbars="none" />
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:stretchMode="columnWidth"
android:scrollbars="none"
android:numColumns="2"
/>
</LinearLayout>
grid_view.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/grid_item_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
<TextView
android:id="#+id/grid_item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_gravity="bottom"
android:textAlignment="center"
android:textColor="#android:color/white"
android:background="#55000000"/>
</FrameLayout>
why you are using gridview in recycler view. it will not behave correctly. if you want a grid view you can use recyclerview as a grid view.
set you recycler view layout manger as StaggeredGridLayoutManager. use it like.
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
take a refreance from https://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html
Your main layout should be scroll view and your recycle view height should not match parent .
you need to set height of grid view dynamically based on number of children.
I'm new to Android have this problem making a scrollview that is supposed to scroll over a ListView of 10+ items.
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.naqishop.naqi.MainActivity"
tools:showIn="#layout/activity_main">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView"
android:entries="#array/options" />
</ScrollView>
</LinearLayout>
The problem is that I can not extend scroll views to show more that one item at a time. I tried to tamper with layout_height of the scrollview (like assigning the value to 500dp)
Also I tried adding
android:fillViewport="true"
as suggestd here
but it did not change the height. So appreciate your hints.
This is because you've set android:layout_height="wrap_content". Replace that with
android:layout_height="match_parent" and it'll take up the whole height.
I have the following android layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:layout_width="match_parent"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:gravity="center"
android:orientation="vertical"
android:background="#3f5561"
android:id="#+id/MainLayout">
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:layout_below="#+id/tabs" />
<com.astuetz.PagerSlidingTabStrip
android:id="#+id/tabs"
app:pstsShouldExpand="true"
app:pstsTextAllCaps="true"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#a97878"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true" />
As you can see, the ViewPager has grey color around it, which is the color of the MainLayout. My question is, how can i set the ViewPager on fullscreen(Without the MainLayout around it). For example like YouTube, PlayStore and ect. That's how i want it to look
How can i possibly do that? Example will be greatly appreciated!
You are adding left, right and top padding to the container, that's why you are getting the grey area. There is no bottom padding so bottom part is ok.
Remove these line from your RelativeLayout
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
you added padding that's why it's showing MainLayout around it, remove padding to apply ViewPager to whole screen
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"