I am trying to add many RecyclerViews dynamically to a LinearLayout depending upon the x coordinate of a 2-D array (Set). All the children of each view are not visible (it appears on scrolling the view).
In short, making the RecyclerView's height to WRAP_CONTENT is not stretching the height of RecyclerView.
I want all the children of all the RecyclerViews to be visible and not let any RecyclerView to be scrollable.
Following is the table_layout which I add dynamically:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Engine"
android:padding="6dp"
android:gravity="center"
android:id="#+id/tv_label"
android:layout_marginTop="16dp"
android:background="#color/light_gray"
android:textSize="#dimen/bid_report_label_text_size"
android:textColor="#color/white"
android:textStyle="bold"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/recycler_view"/>
</LinearLayout>
Following is the activity_main layout of activity:
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button_bid_now"
android:id="#+id/scrollView">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linear_layout_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="210dp"
android:id="#+id/bike_image"
android:onClick="startImageSlideshow"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linear_layout_details"
android:orientation="vertical"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I add table_layout to activity_main dynamically.
Please tell me how to make the RecyclerView WRAP_CONTENT?
The problem was with ScrollView. Changing it to NestedScrollView solved the problem.
Related
My situation is simple. I have one RecyclerView and inside it is a few other RecyclerViews. The internal RecyclerViews do not scroll when I try to scroll them.
Why is this? Is there a workaround?
Root XML with root RecyclerView:
<?xml version="1.0" encoding="utf-8"?>
<com.boxed.v2.ui.category.SortAndFilterView android:id="#+id/sortfilterview"
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:layout_marginTop="?actionBarSize"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:elevation="3dp"
app:contentViewId="#+id/content"
app:progressViewId="#+id/progressbar"
app:secondaryViewId="#+id/error">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:layout_marginTop="55dp"
android:paddingTop="10dp"
android:clickable="true"
android:orientation="vertical">
<TextView
android:id="#+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/bright_teal"
android:text="Sort & Filters"
android:paddingLeft="12dp"
app:fontName="#string/font_sofia_medium"
android:textAllCaps="false"
android:textSize="24sp"
/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/recycler_view"
android:background="#color/white"
android:orientation="vertical"
android:layout_margin="10dp"
></android.support.v7.widget.RecyclerView>
</LinearLayout>
</com.boxed.v2.ui.category.SortAndFilterView>
Then, nested item view containing nested RecyclerView (one of these per row in the root RecyclerView):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/textlines"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/text_view"
android:layout_width="match_parent"
android:height="55dp"
android:layout_height="wrap_content"
app:fontName="#string/font_sofia_medium"
android:textAllCaps="false"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="18sp" />
<LinearLayout
android:id="#+id/collapsable_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/embedded_recycler_view"
android:layout_width="match_parent"
android:layout_height="190dp"
android:background="#drawable/textlines"
></android.support.v7.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
The LayoutManager gets Confused on which View to scroll,
To make the inner RV to scroll do this.
Create a NestedScrollView inside the Top RV
Then inside the NestedScrollView Put your second RV
NB
RV = recyvlerView
For a RecyclerView to scroll, one of two things must be true:
The RecyclerView has a smaller height than all of its items
The RecyclerView is inside a scrolling parent
In your case embedded_recycler_view height must be less then collapsable_content ( you have use match_parent and that is wrong) or you add another scrollview inside collapsable_content and then added embedded_recycle
then
set setHasFixedSize to true and also set setRecycledViewPool for child
I have a huge list of items which I put into linear layout and then I put that into scrollview to make it scrollable.
Then I wrap it all into relative view because I want to have add button at the bottom.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
A LOT OF CONTENT
</LinearLayout>
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="#+id/add"
android:text="#string/add"
android:paddingTop="23dp"/>
</RelativeLayout>
Due to add button at the bottom whenever I scroll to the very bottom of the list, the add button blocks the bottom most part of the scrollview. How would I have scrollview fit only the part of screen that add button does not take up?
Set rule android:layout_above="#+id/add" to ScrollView.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_above="#+id/add"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
A LOT OF CONTENT
</LinearLayout>
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="#+id/add"
android:text="#string/add"
android:paddingTop="23dp"/>
</RelativeLayout>
Add this to the scroll View:
android:layout_above="#+id/add"
I have a LinearLayout with 3 children with weights to set their proportions: 1/7, 3/7, 3/7. The last section contains text that could extend outside the space allowed, so I added a scrollview.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:orientation="vertical"
android:background="#drawable/package_status_border"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3">
<TextView
android:id="#+id/PackageContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
</LinearLayout>
This layout is working fine if the PackageContent text is small:
expected formatting
But, if the PackageContent text is large, rather than maintaining the expected height and just scrolling the extra text it is filling the entire screen:
bad formatting, with scroll view filling entire screen
How to I make sure that the last section is still only 3/7 of the screen, with content scrolling, regardless of how much content the textView contains?
I have also tried putting the ScrollView within its own LinearLayout but that did not work either.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:orientation="vertical"
android:background="#drawable/package_status_border"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/PackageContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
</FrameLayout>
</LinearLayout>
I am trying to put RecyclerView inside ScrollView, I Have layout above the recycler view, so I want to scroll both layout and recycler while scrolling.
In My main Layout I have two sub Layout , and one of the have recyclerView and another one Have an Image .Both layout inside a scrollView. When I scrolling up in the layout , I want to scroll both
I know the issue that we cant put two scroll view in one layout.
Am searching is there any logic that we can scroll both layout and recycler View
Layout.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"
android:background="#color/backgorund"
android:weightSum="1">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:id="#+id/layout_top_balance"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txt_balance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="35dp"
android:textColor="#color/black"
android:text="$60 USD"/>
<TextView
android:layout_below="#+id/txt_balance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="20dp"
android:textColor="#828282"
android:text="Account Balance"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_feeds"
android:layout_width="match_parent"
android:layout_height="0dp"
android:paddingLeft="16dp"
android:paddingBottom="5dp"
android:layout_weight=".75">
<view
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="android.support.v7.widget.RecyclerView"
android:id="#+id/recycler_view"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Cam any one please help for solving this issue:)
It is not recommended to scroll inside scroll in android. Recycler view is itself a scroll. Seems you want a scrollable portion above a list "layout_top_balance". Add this view as header of recycler view and remove scrollview. This will solve your problem.
You can use this recycle view lib if you want to add header
RecyclerViewHeader Example 1
RecyclerViewHeader Example 2
I want to programatically add viwes to vertical orientation linearlayout within horizontalscrollview within Scrollview. Basic scheme of my layout is belowe:
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:fadingEdge="none">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- same header code -->
</LinearLaout>
<HorizontalScrollView
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<LinearLayout
android:id="#+id/list_view"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"/>
</HorizontalScrollView>
</ScrollView>
Now if i'm adding programatically 5 views to list_view linearlayout, i get only one view, and free sapce below it. If i comment HorizontallScrollView like that:
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:fadingEdge="none">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- same header code -->
</LinearLaout>
<LinearLayout
android:id="#+id/list_view"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"/>
</ScrollView>
All views are show correct, but they aren't horizontall scrollable. Please give me same ideas how to solve this problem.
Answer is to change linearlayout's android:layout_width attribute to wrap_content within horizontalScrollview