Reputation: 1317
I am working on a screen which has one tool bar information of a product and list of similar products.
<RelativeLayout>
<toolbar />
<Scrollbar>
<LinearLayout>
<ProductInfo />
<TextView > <!--Similar products -->
<RecyclerView />
</LinearLayout>
</Scrollbar>
Everything is working fine except scroll. Scroll is not smooth when recyclerview comes on screen. I think the idea should be to have recycler view without its own scrollbar. Because now it seems like i'm ending up with two scrollbars which is making scrolling painful. Is there a way through which i can disable scrollbar of recyclerview and stretch it to to occupy required height and parent scrollbar scroll my screen smoothly?
I'm using staggeredGridLayoutManager so I can use both productinfo view and similar products as card in single Recyclerview, as ProductINfo will need complete width of the screen where as for similar product i need two column. Please help Code:
> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:navigationIcon="?attr/homeAsUpIndicator" android:background="@color/primary" android:elevation="10dp" /> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/scrollView" android:fillViewport="true"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="?attr/actionBarSize"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/imgProduct" android:elevation="10dp" android:src="@drawable/placeholder" android:layout_margin="10dp" android:background="#ffffff" /> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/view" android:showDividers="end"> <FrameLayout android:id="@+id/frame" android:layout_width="60dp" android:layout_height="60dp"> <ImageView android:layout_width="60dp" android:layout_height="60dp" android:id="@+id/imgProfile" android:src="@drawable/ic_action_profile_black" /> <ImageView android:id="@+id/circle_crop" android:layout_width="60dp" android:layout_height="60dp" android:src="@drawable/circle_crop" /> </FrameLayout> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="20dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Medium Text" android:id="@+id/txtUserName" android:layout_gravity="center_vertical" android:textColor="@color/primary_text" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:text="Small Text" android:id="@+id/txtTime" /> </LinearLayout> </LinearLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Medium Text" android:id="@+id/txtProductName" android:layout_marginLeft="20dp" android:textColor="@color/primary_text" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Medium Text" android:id="@+id/txtDescription" android:layout_marginLeft="20dp" /> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:paddingLeft="5dp" android:paddingRight="5dp" android:id="@+id/tagsContainer"> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:paddingLeft="5dp" android:paddingRight="5dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="10 Likes" android:id="@+id/txtLikes" android:layout_weight="1" android:textSize="16sp" android:textAlignment="center" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="10 Comments" android:id="@+id/txtComments" android:layout_weight="1" android:textSize="16sp" android:textAlignment="center" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="100 Times viewed" android:id="@+id/txtViews" android:layout_weight="1" android:textSize="16sp" android:textAlignment="center" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" > <ImageView android:layout_width="wrap_content" android:layout_height="30dp" android:id="@+id/imgLike" android:src="@drawable/ic_action_like_black" android:layout_weight="1" android:layout_gravity="center_vertical" /> <ImageView android:layout_width="wrap_content" android:layout_height="30dp" android:id="@+id/imgComment" android:src="@drawable/ic_action_comment_black" android:layout_weight="1" android:layout_gravity="center_vertical" /> <ImageView android:layout_width="wrap_content" android:layout_height="30dp" android:id="@+id/imgShare" android:src="@drawable/ic_action_share_black" android:layout_weight="1" android:layout_gravity="center_vertical" /> <Button android:layout_width="wrap_content" android:layout_height="30dp" android:text="Buy" android:id="@+id/btnBuy" android:background="@drawable/btncorner" android:layout_margin="10dp" android:textColor="@color/primary_text" android:elevation="10dp" android:layout_weight="1" android:layout_gravity="center_vertical" /> </LinearLayout> </LinearLayout> </LinearLayout> </android.support.v7.widget.CardView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Loading Similar Products.." android:id="@+id/txtSimilarProducts" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="5dp" /> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@id/feedContainer" android:scrollbars="none"> </android.support.v7.widget.RecyclerView> </LinearLayout> </ScrollView>
Upvotes: 0
Views: 826
Reputation: 1263
For smooth scrolling you should use <ScrollView>
instead of <ScrollBar>
.
Upvotes: 1