Horizontal ScrollView in fragment Android - android

I would like to make my ScrollView filling out the full layout of a fragment and scrolling horizontally, not vertically.
How can I achieve that?!
Like the album covers
Thanks

Its not vertically, it is horizontally
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
// Add your ImageButtons
</LinearLayout>
</HorizontalScrollView>

You have to set the scrollview to
android:fillViewport="true"
Below is the complete code
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/myscrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
</ScrollView>

Related

ScrollView padding cut off items

I try set padding on my ScrollView that contain LinearLayout, but i noticed that the first/last items cutting off.
Its seem like the ScrollView padding himself with the background, but don't notify a LinearLayout about that.
anyone know whay this happe?
Thanks..
My code:
<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"
android:padding="20dp"
tools:context="com.example.aviad.scrollview.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="40dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:fillViewport="true"
android:background="#54d45f"
android:paddingTop="15dp"
android:paddingBottom="15dp">
<LinearLayout
android:id="#+id/conteiner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
</ScrollView>
</android.support.constraint.ConstraintLayout>
Result:
enter image description here
Just add android:clipToPadding="false" to your LinearLayout

set LinearLayout on center android

I have one LinearLayout in which there are two components one is SquareLayout and second one is RecyclerView, i want SquareLayout in center of the screen and RecyclerView in bottom of the screen , don't know why but gravity not work for set it. i am new in android i hope my question is clear. Here is my .xml file..
<LinearLayout 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:orientation="vertical" >
<com.example.layouts.SquareLayout
android:id="#+id/llSelectedLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
></com.example.layouts.SquareLayout>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rvImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
Use RelativeLayout instead of LinearLayout for do that.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.example.gridcollagelayouts.SquareLayout
android:id="#+id/llSelectedLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:centerInParent="true" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rvImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:below="#+id/llSelectedLayout" />
</RelativeLayout>

Android scroll Framelayout that changes dimensions

I have a FrameLayout in a ScrollView like bellow:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_weight="1"
android:scrollbars="vertical">
<FrameLayout
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:background="#ffffff">
</FrameLayout>
</ScrollView>
In this framelayout I draw a view that changes dimensions depending on drawing parameters.
The problem is that if the drawing is out of screens bound the view that I draw does not scroll.
I'm using a framelayout because I need to draw views over views.
What can i do in this situation?
Thanks for the help.

NestedScrollView could not scroll with match_parent height child

I implement NonSwipeableViewPager with a fragment has NestedScrollView like this, what I expect is that the scrollview can scroll up and show 2 textviews:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="#layout/header" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"
android:src="#drawable/ic_up" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text 1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text 2" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
But it could not scroll, I tried many ways but still did not get any solution
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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">
This linearlayout should have android:layout_height="wrap_content".
Reason for that is that if the scrollview's child is the same size as the scrollview itself (both match_parent for height) it means that there is nothing to scroll through, since they are of same size and the scrollview will only be as high as the screen.
If the linearlayout has a height of wrap_content then the height is not related to the height of the screen and the scrollview will be able to scroll through it.
Just remember that a scrollview can only have 1 direct child, and that child needs android:layout_height="wrap_content"
In my case app:layout_behavior="#string/appbar_scrolling_view_behavior" this is working only if some one face problem will be try it and may be solve your problem too. you should add also android:fillViewport="true" but without this my code working.
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/subscription_background"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
For me it worked when i added "android:layout_marginBottom="100dp"" for last child in androidx.core.widget.NestedScrollView
if you have used netedscrollview as follow you have to use
android:scrollbars="vertical"
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#id/toolbar_updateUserDetails"
app:layout_constraintBottom_toBottomOf="parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="vertical"
>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
You have to calculate your other child because last child binding on nestedScrollView. You add margin like child height. It is working.

How can I add horizontal, vertical RecyclerView inside a vertical scroll

I want to add vertical as well as horizontal RecyclerViews inside a vertical scrollview.
Is it possible to have multiple recycler views inside vertcal scrollview
what control I need to use.
Also RecyclerView nested in one ScrollView is not good practice so can anybody tell me whats right way to do it can I add RecyclerView inside another RecyclerView or I need to use horizontal and vertical scrollview only to achieve this.
You can do something like this for getting two RecyclerView nested in one ScrollView which is by the way not recommended.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/tools"
android:focusableInTouchMode="true"
android:padding="8dp"
android:background="#drawable/old_map"
android:layout_height="match_parent">
<ScrollView
android:layout_below="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:scrollbars="none">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="600dp">
<view
android:scrollbarSize="6dp"
android:id="#+id/recent_post"
class="android.support.v7.widget.RecyclerView"
android:layout_width="match_parent"
android:layout_height="400dp"
android:scrollbars="vertical" />
<view
android:scrollbarSize="6dp"
android:id="#+id/recent_post"
class="android.support.v7.widget.RecyclerView"
android:layout_width="match_parent"
android:layout_height="400dp"
android:scrollbars="horizontal" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I don't namely know what kind of scrolling do you want but it is possible to use both scrolls at the same time:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:id="#+id/HorizontalScrollView02"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- HERE YOUR CODE-->
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>

Categories

Resources