TextViews below recyclerview are not displaying - android

The TextViews Below RecyclerView are not displaying.The whole screen is occupied by RecyclerView.If i use Nestedscrollview only TextViews are displaying but not RecyclerView.Please Anyone provide solution for this
<LinearLayout
android:id="#+id/wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/wrapper"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
</LinearLayout>
</RelativeLayout>

this will divide your screen in two parts first half will be covered by recyclerview and another by textviews.
try this.
<LinearLayout
android:id="#+id/wrapper"
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_below="#+id/wrapper"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
</LinearLayout>

You can use NestedScrollView if you want to display RecycleView with other Views like (TextView, Button another recycleView ....) like this example:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="2dp"
android:layout_marginStart="2dp"
android:layout_marginEnd="2dp">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/trending"
android:supportsRtl="true"
android:textColor="#color/colorPrimary"
android:textSize="14sp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_stores"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>

Related

Android : How to Create Dividers between Components

My goal is to obtain divider lines similar to the ones shown in the following picture:
Goal Picture Divider
I need to place a horizontal and vertical divider between LinearLayout
This is my User Interface XML Code:
<?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_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#drawable/maingradiant">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="اطلاعات ورودی"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="فاکتور"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="هزینه ها"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="تسویه"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="سامانه"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ارسال بار"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I am currently using RelativeLayout as the Root Element, and for each row, I am applying a horizontal LinearLayout followed by a vertical LinearLayout.
Based on my current layout, can I receive assistance on how to place the divider lines on my interface, much like the provided picture?
Thank you!
First of all, I would recomend you to use RecyclerView with GridLayoutManager for this purpose. creating recyclerview with gridmanager
but if you want stick with current design, you add line by creating a View in xml
For Vertical line
<View
android:layout_width="2dp" //thickness
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
For Horizontal line
<View
android:layout_width="match_parent"
android:layout_height="2dp"//thickness
android:background="#color/colorPrimary" />
for shading colors you should look for something like Gradient in android. How ro create Gradient in android
code looks like this.
<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_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/maingradiant"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="اطلاعات ورودی"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="فاکتور"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="هزینه ها"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="تسویه"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="سامانه"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ارسال بار"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Happy coding!!

Android: ScrollView with text scrolling over imageview

I'm trying to setup text to initially start under an image and step over it and cover as you scroll up.
<FrameLayout 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"
tools:context="com.example.rcarb.testlayout.MainActivity">
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:src="#drawable/ic_android_black_24dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="300dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" /> //More textviews
The text keeps disappearing behind the imageview or at the padding border of the scrollview. I was under the impression that if you add padding to the top of the scrollview it would add to the body of the scrollview not a thicker border.
https://github.com/rcarbal/TestLayout
Thank you in advance.
Even when you scroll, the padding of 300dp stays, and that's why your textviews go behind the image.
So instead of adding a padding to your scrollview, put an empty textview (or any layout) with the required height (300 dp here) inside the scrollview.
Code goes something like this:
<FrameLayout 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"
tools:context="com.example.rcarb.testlayout.MainActivity">
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:src="#drawable/ic_android_black_24dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="300dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HELLO"
android:textSize="50sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>

Recyclerview inside linearlayout scrolling smoothly

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>
For smooth scrolling you should use <ScrollView> instead of <ScrollBar>.

layout_weight is not working at all [duplicate]

This question already has answers here:
Layout Weights do not work inside a ScrollView
(5 answers)
Closed 6 years ago.
The problem is that I want two linearlayouts inside a linearlayout.And I want those 2 linearlayouts to be aligned vertically according to android:layout_weight property.But it seems that layout_weight is not having any effect. Here is my layout
<ScrollView>
.....
<LinearLayout>
...
<LinearLayout> //1.Here the Linear Layout is not getting aligned properly according to the layout_weight
...
android:layout_height="0dp"
android:layout_weight="3"
.
.
.
.
</LinearLayout>
<LinearLayout> //2.These two Linear layouts are to be aligned vertically and this second layout is required to use very less space as compared to first layout
. . .
android:layout_height="0dp"
android:layout_weight="1"
.
.
.
</LinearLayout>
</LinearLayout>
</ScrollView>
Here is the full XML code for reference:
<ScrollView 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=".MainActivity">
<LinearLayout
android:layout_margin="16dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="3" >
<EditText
android:id="#+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="30dp"
android:ems="5"
android:hint="Name"
android:inputType="text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Toppings"
android:textAllCaps="true" />
<CheckBox
android:id="#+id/whippedcream_checkbox_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:paddingLeft="24dp"
android:text="Whipped Cream"
android:textSize="16sp" />
<CheckBox
android:id="#+id/chocolate_checkbox_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:paddingLeft="24dp"
android:text="Chocolate"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Quantity"
android:textAllCaps="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="48dp"
android:layout_height="48dp"
android:onClick="decrement"
android:text="-" />
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="2"
android:textColor="#android:color/black"
android:textSize="16sp" />
<Button
android:layout_width="48dp"
android:layout_height="48dp"
android:onClick="increment"
android:text="+" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="order summary"
android:textAllCaps="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="submitOrder"
android:text="Order" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PRICE:" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Coffee: Rs.5 per cup" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Whipped Cream: Rs.1 per cup additional" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chocolate: Rs.2 per cup additional" />
</LinearLayout>
</LinearLayout>
</ScrollView>
add android:fillViewport="true" in scrollview
add android:weightSum="4" main linearlayout
Here is the full code below,
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:fillViewport="true"
tools:context=".DemoActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:orientation="vertical"
android:weightSum="4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:orientation="vertical">
<EditText
android:id="#+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="30dp"
android:ems="5"
android:hint="Name"
android:inputType="text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Toppings"
android:textAllCaps="true" />
<CheckBox
android:id="#+id/whippedcream_checkbox_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:paddingLeft="24dp"
android:text="Whipped Cream"
android:textSize="16sp" />
<CheckBox
android:id="#+id/chocolate_checkbox_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:paddingLeft="24dp"
android:text="Chocolate"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Quantity"
android:textAllCaps="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="48dp"
android:layout_height="48dp"
android:onClick="decrement"
android:text="-" />
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="2"
android:textColor="#android:color/black"
android:textSize="16sp" />
<Button
android:layout_width="48dp"
android:layout_height="48dp"
android:onClick="increment"
android:text="+" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="order summary"
android:textAllCaps="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="submitOrder"
android:text="Order" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PRICE:" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Coffee: Rs.5 per cup" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Whipped Cream: Rs.1 per cup additional" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chocolate: Rs.2 per cup additional" />
</LinearLayout>
</LinearLayout>
All content inside both the linear layouts has their layout_height set as wrap_content.
The important thing here is that, weights work only after all views having not weighted layout_height/layout_width have occupied space on the screen.
Example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="abcd1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="abcd2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="abcd3" />
</LinearLayout>
Here abcd2 and abcd3 TextViews would be alloted space first and then abcd1 would occupy the rest of the space on the screen.

3 equal height rows in a ScrollView

Here is my layout XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#mipmap/banner" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:id="#+id/row2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 1"
android:textColor="#color/darkBlue"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyRecipes"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAll1"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:layout_below="#id/row2" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:id="#+id/row3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 2"
android:textColor="#color/darkBlue"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyFavorites"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAllFavorites"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:layout_below="#id/row3" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
As you can see from my layout, the outer LinearLayout contains 3 RelativeLayout which all have layout_weight equals to 1 and the LinearLayout has weightSum equal to 3.
However, the behavior of the current layout is: The 1st RelativeLayout shared very little space (around 10%) and the 2nd & 3rd RelativeLayout shared 45% of height.
How can I make them equally shared the height?
Add to below attributes to ScrollView
android:layout_centerVertical="true"
android:fadingEdge="none"
android:fillViewport="true"
android:isScrollContainer="true"
Check layout below
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:fadingEdge="none"
android:fillViewport="true"
android:isScrollContainer="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#mipmap/banner" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="#+id/row2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 1"
android:textColor="#color/blue_360"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyRecipes"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAll1"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row2"
android:paddingBottom="5dp"
android:paddingTop="5dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="#+id/row3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 2"
android:textColor="#color/blue_360"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyFavorites"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAllFavorites"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row3"
android:paddingBottom="5dp"
android:paddingTop="5dp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
Because your using scrollview you need to fill your view port to make the scroll view occupy the whole screen
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"/>
//..... your other code here
</ScrollView>

Categories

Resources