Align Recycler View above linear layout - android

The list of things expected in the outout
1.a linear layout to the buttom of the activity as shown in the expected image
2.a recycler view above the linear layout to achieve the scrolling funtionality as shown in the expected image
The problem can be solved if I give the height to the recycler view.But in this case the layout won't be responsive to the samller sized screens
How can I achieve it?
xmlfile.xml
<?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:numberpicker="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:orientation="vertical"
tools:context=".CartPage">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:padding="20dp">
<ImageView
android:id="#+id/back_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:src="#drawable/ic_arrow_back_black_24dp" />
<TextView
android:id="#+id/product_buy"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/back_icon"
android:fontFamily="#font/carter_one"
android:text="My Cart"
android:textColor="#color/black"
android:textSize="20sp"
tools:ignore="RtlCompat" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/product_recycler"
android:layout_width="match_parent"
android:layout_height="400sp"
android:padding="0dp" />
// this is the buttom recycler
<LinearLayout
android:layout_alignParentBottom="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/buttom"
android:gravity="bottom|end"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border_gray"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="#+id/details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border_gray"
android:fontFamily="sans-serif"
android:lineHeight="28dp"
android:padding="5dp"
android:text="Price Details"
android:textColor="#color/grey_400"
android:textSize="18sp"
tools:ignore="RtlCompat" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

If you wish to tell your RecyclerView to fill the left over space of your LinearLayout you have to use the following layout_height and layout_weight on your RecyclerView:
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/product_recycler"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:padding="0dp" />

Related

How to align buttons side by side in scroll view?

I just started using android studio.. I am trying to align ImageButtons inside a scroll view side by side, but i cannot put them side by side, neither can i resize them from the left side. How do i align them side by side?
I already tried the solution given in one of the answers: Aligning TextView Side By Side Inside A ScrollView Inside a Linear Layout but it didn't work
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".StoryIndex">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageButton
android:id="#+id/titlee"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/black"
app:srcCompat="#drawable/alami1" />
<ImageButton
android:id="#+id/imageButton8"
android:layout_width="375dp"
android:layout_height="116dp"
android:background="#android:color/black"
app:srcCompat="#drawable/alami2" />
<ImageButton
android:id="#+id/imageButton9"
android:layout_width="195dp"
android:layout_height="169dp"
app:srcCompat="#drawable/alami3" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
I want the Image buttons to be side by side, but they are in rows, on top of each other.. but it shows like the one in picture:
Image of the design view
Thanks.
You have to change the orientation in LinearLayout from vertical to horizontal.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Try this
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
//The question you mentioned can be obtained by using weightSum
android:weightSum="15">
//replace src ic_launcher_background by your drawable source.
<ImageButton
android:id="#+id/titlee"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:src="#drawable/ic_launcher_background" />
<ImageButton
android:id="#+id/imageButton8"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:src="#drawable/ic_launcher_background" />
<ImageButton
android:id="#+id/imageButton9"
android:layout_width="0dp"
android:layout_weight="5"
android:background="#android:color/black"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher_background"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Try this and let me know. Happy coding.
<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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="15">
<ImageButton
android:id="#+id/imageButtonOne"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:src="#drawable/ic_launcher_background" />
<ImageButton
android:id="#+id/imageButtonTwo"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:src="#drawable/ic_launcher_background" />
<ImageButton
android:id="#+id/imageButtonThree"
android:layout_width="0dp"
android:layout_weight="5"
android:background="#android:color/black"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher_background"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Try this if you still find any issue, let me know.
Show the Image buttons to be side by side, and in rows.
Change the orientation of LinearLayout from vertical to horizontal.
Please try below code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="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="horizontal">
<ImageButton
android:id="#+id/titlee"
android:layout_weight=".3"
android:layout_width="0dp"
android:layout_height="116dp"
android:background="#android:color/black"
app:srcCompat="#drawable/stars_one"
android:layout_margin="4dp"/>
<ImageButton
android:layout_weight=".4"
android:id="#+id/imageButton8"
android:layout_width="0dp"
android:layout_height="116dp"
android:background="#android:color/black"
app:srcCompat="#drawable/stars_one"
android:layout_margin="4dp"/>
<ImageButton
android:layout_weight=".3"
android:id="#+id/imageButton9"
android:layout_width="0dp"
android:layout_height="116dp"
app:srcCompat="#drawable/stars_one"
android:layout_margin="4dp"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
The output of above code is like:

scrollbar in constraint layout not working

I have tried the below code but it doesn't scroll when I rotate my application it will cover most of screen but I need to scroll there it doesn't working there. Is it right way to use scroll view in constraint layout. I have seen this type of example. There it was in working condition I have tried the below code but it doesn't scroll when I rotate my application it will cover most of screen but I need to scroll there it doesn't working there. Is it right way to use scroll view in constraint layout. I have seen this type of example.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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">
<include layout="#layout/tool_bar" />
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="611dp"
android:layout_marginTop="70dp"
android:scrollbars="none"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:id="#+id/main_bmi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/bmi" />
<ImageView
android:id="#+id/bmr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/bmr" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:id="#+id/ideal_weight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ideal" />
<ImageView
android:id="#+id/water_intake"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/water" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:id="#+id/calorie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/calories" />
<ImageView
android:id="#+id/nutrition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nutrition" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
follow this layer it might work.put appbarlayout inside ConstraintLayout layout
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--add your scrollview or nestedscrollview here-->
</LinearLayout>
</android.support.design.widget.AppBarLayout>
Your ScrollView height is fixed to 611dp.
If you use a fixed size, then the content should be greater than 611dp to be able to scroll.
You should use
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
....>

Scrollview not showing last item in layout

Here is the code that i'm facing the problem i took 2 linear layout inside scroll view now the last button inside 2nd linear layout is hidden or i can say not showing properly.
Here is the screen shot.
you can check that i selected area is button but not working properly.
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:id="#+id/ConcernedPortionofScreen"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="#+id/RestofScreen"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.75"
android:orientation="vertical"
android:padding="20dp">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/custom_button_shape_with_bg_primary"
android:minHeight="#dimen/minimum_height_all_object"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:text="SELECT"
android:textColor="#color/white"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
when i try to remove layout_weight my layout getting mass.
<android.support.constraint.ConstraintLayout 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="#android:color/white"
android:orientation="vertical"
tools:context=".MainActivity">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:id="#+id/ConcernedPortionofScreen"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:orientation="vertical">
<!-- Parent FrameLayout 'FL' -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Conitans Tree Childs -->
</FrameLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/RestofScreen"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.75"
android:orientation="vertical"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<!--Conitans Two Childs -->
</LinearLayout>
<EditText
style="#style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:hint="Enter Child Name"
android:minHeight="#dimen/add_child_rquest_minimum_height_all_object" />
<EditText
style="#style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:hint="Select City"
android:minHeight="#dimen/add_child_rquest_minimum_height_all_object" />
<TextView
style="#style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:hint="Select Birthdate"
android:minHeight="#dimen/add_child_rquest_minimum_height_all_object" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<!--Conitans Two Childs -->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<!--Conitans Two Childs -->
</LinearLayout>
<EditText
style="#style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:hint="Enter Mobile Number"
android:minHeight="#dimen/add_child_rquest_minimum_height_all_object" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<!--Conitans Two Childs -->
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:fontFamily="#font/segoe_ui_bold"
android:paddingLeft="10dp"
android:text="Note / Message :"
android:textColor="#color/colorPrimaryDark"
android:textSize="18dp" />
<EditText
style="#style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:inputType="textMultiLine"
android:lines="8"
android:maxLines="8"
android:minHeight="#dimen/add_child_rquest_minimum_height_all_object"
android:minLines="8"
android:scrollbars="vertical" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:background="#drawable/custom_button_shape_with_bg_primary"
android:fontFamily="#font/segoe_ui_bold"
android:minHeight="#dimen/add_child_rquest_minimum_height_all_object"
android:text="SUBMIT"
android:textColor="#color/white" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
This Happends Because of layout_height="match_parent" for ScrollView child LinearLayout
Change layout_height to wrap_content
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
//android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
//childs ..........
</LinearLayout>
<ScrollView>
wrap_content
Setting a View's size to wrap_content will force it to expand only far enough to contain the values (or child controls) it contains. For controls -- like text boxes (TextView) or images (ImageView) -- this will wrap the text or image being shown. For layout elements it will resize the layout to fit the controls / layouts added as its children.
Official Docs Says
FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding)
WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding)
Use nested Scroll View, scroll view will truncate the last item in the layout
add padding from bottom and check.
android:layout_marginBottom="5dp"
android:layout_paddingBottom="10dp"
The simplest solution is placing ConstraintLayout inside ScrollView like this
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical">
<!-- your other views could be here-->
<!-- your other views could be here-->
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

RecyclerView does not expand its height when an item is added on adapter

I have a layout containing a RecyclerView and a layout for handling showing more items. When one or more items are received from hitting the "Show more" button the adapter is notified and the items are added on the RecyclerView. But the problem is, that the RecyclerView's height after an item has been added is not expanded.
This layout is part of a fragment contained in a ViewPager under a CollapsingToolbarLayout.
The structure of the fragment's layout:
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#f5f5f5">
<com.github.rahatarmanahmed.cpv.CircularProgressView
android:id="#+id/progress_view"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
app:cpv_animAutostart="true"
app:cpv_indeterminate="true"
app:cpv_thickness="4dp"/>
<LinearLayout
android:id="#+id/list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/reviews_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#+id/show_more_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#eee">
<TextView
android:id="#+id/show_more_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Show More"
android:textSize="15sp"
android:textColor="#color/colorPrimary"/>
<com.github.rahatarmanahmed.cpv.CircularProgressView
android:id="#+id/show_more_progress_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:visibility="invisible"
app:cpv_animAutostart="true"
app:cpv_indeterminate="true"
app:cpv_thickness="3dp"/>
</FrameLayout>
</LinearLayout>
</FrameLayout>
And the current state is something like this:
And the black part of image is the device's available height.
Check this modified layout.
Adding weight to recyclerview and the button wil make it fixed in particular position.Hope it works for you.
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#f5f5f5">
<com.github.rahatarmanahmed.cpv.CircularProgressView
android:id="#+id/progress_view"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
app:cpv_animAutostart="true"
app:cpv_indeterminate="true"
app:cpv_thickness="4dp"/>
<LinearLayout
android:id="#+id/list_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/reviews_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"/>
<FrameLayout
android:id="#+id/show_more_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:background="#eee">
<TextView
android:id="#+id/show_more_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Show More"
android:textSize="15sp"
android:textColor="#color/colorPrimary"/>
<com.github.rahatarmanahmed.cpv.CircularProgressView
android:id="#+id/show_more_progress_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:visibility="invisible"
app:cpv_animAutostart="true"
app:cpv_indeterminate="true"
app:cpv_thickness="3dp"/>
</FrameLayout>
</LinearLayout>
Change your LinearLayout to a RelativeLayout, anchor FrameLayout to bottom parent and RecyclerView above your FrameLayout as follow:
<RelativeLayout android:id="#+id/list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.RecyclerView
android:id="#+id/reviews_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/show_more_container" />
<FrameLayout
android:id="#+id/show_more_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#eee">
<TextView
android:id="#+id/show_more_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Show More"
android:textSize="15sp"
android:textColor="#color/colorPrimary"/>
<com.github.rahatarmanahmed.cpv.CircularProgressView
android:id="#+id/show_more_progress_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:visibility="invisible" />
</FrameLayout>
</RelativeLayout>
Change RecyclerView height to match_parent
change the layout_height of linearlayout to match_parrent.
change the layout_height of recyclerview to match_parrent.
change your recyclerviews item's height to wrap_content.
try this
Replace this
<LinearLayout
android:id="#+id/list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
to
<LinearLayout
android:id="#+id/list_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
Also change the Recyclerview height to match_parent

Scroll layout wouldn't show one of my views?

I want to have the following layout :
But when I run the code the first linear layout which contains a relative layout and an image is shown correctly.
Then there is the "view pager" but it is not on the screen.
and then there is a text box and a button which are there too.
So why my view pager is missing?
<?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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
tools:ignore="NestedWeights,ContentDescription" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5" >
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:src="#drawable/sp_page_name"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:padding="#dimen/product_views_horizontal_padding"
tools:ignore="NestedWeights" >
</RelativeLayout>
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager_sharepoint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/TODO"/>
<TextView
android:id="#+id/sharepoint_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/sharepoint_description"
tools:ignore="SelectableText" />
<ImageButton
android:id="#+id/sp_more_info"
android:layout_width="70dp"
android:layout_height="30dp"
android:background="#drawable/more_info_icon"
android:layout_gravity="left"
android:onClick="sp_more"/>
</LinearLayout>
</ScrollView>
The height of your ViewPager is android:layout_height="wrap_content".
So if your ViewPager doesn't contain other views, it won't be visible.
Well, I found out that scrolling views do not work very good together.
For my layout I solve the problem by changing the height and width of the viewpager to static sizes. Actually I defined some different sizes in my dimen.xml files for different screen sizes and use them for the height and width of my view pager.
Here is the code:
<?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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
tools:ignore="NestedWeights,ContentDescription" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5" >
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:src="#drawable/sp_page_name"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:padding="#dimen/product_views_horizontal_padding"
tools:ignore="NestedWeights" >
</RelativeLayout>
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager_sharepoint"
android:layout_width="#dimen/viewpager_width"
android:layout_height="#dimen/viewpager_height"
android:contentDescription="#string/TODO"/>
<TextView
android:id="#+id/sharepoint_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/sharepoint_description"
tools:ignore="SelectableText" />
<ImageButton
android:id="#+id/sp_more_info"
android:layout_width="70dp"
android:layout_height="30dp"
android:background="#drawable/more_info_icon"
android:layout_gravity="left"
android:onClick="sp_more"/>
</LinearLayout>
</ScrollView>

Categories

Resources