Can not scroll my LinearLayout - android

I have a layout and try to make the components inside it scrollable, it shall be able to scroll the listView and Pdf-View and also it shall be able to scroll the ListView and Pdf-View together
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".uiFragments.HerstellerunterlagenInstandhalterFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/back"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
<ListView
android:id="#+id/listview_anlagenuebersicht_instandhalter"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:listSelector="#drawable/bkg"
android:background="#android:color/white"
android:layout_height="70dp"
android:layout_width="650dp"/>
</LinearLayout>
<com.github.barteksc.pdfviewer.PDFView
android:id="#+id/pdfView_anlage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"/>
</LinearLayout>
</ScrollView>
</FrameLayout>
I want to "scroll" my PDF-Viewer and Listview, together, but it does not work, I can only scroll my listView and the pdf-view separately

You can use android:isScrollContainer="true". It will indicate that the view is one of the set of scrollable containers in its window. For more read this https://developer.android.com/reference/android/view/View

Because list view has its own scroll view you can not add it inside another scroll view so you must use them isolated

Related

How to make a horizontal recyclerview appear bottom of the screen?

I wanna to build the layout like the diagram below. When I click the button a horizontal recyclerView slide up and appear at the bottom of the screen under the LinearLayout which contain the button.
I looking to use bottom sheet.When the bottom sheet with recyclerView appear,but it cover the whole LinearLayout which contain the button.Here is my layout xml:
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true">
<LinearLayout
android:id="#+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/white"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#null"
android:text:"Button"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/horizontalRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_anchor="#id/bottomBar"
android:animateLayoutChanges="false"
android:scrollbars="horizontal"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"/>
</android.support.design.widget.CoordinatorLayout>
So my question is,how can I make the horizontal recyclerView slide up and appear from the bottom of the screen? Am I going the right direction? Or have a better approach to achieve this?
Thanks in advance.
You can achieve that in simple steps:
First keep your linear Layout orientation vertical by adding this.
android:orientation="vertical"
And then add recycler view below button inside linearLayout.Whenever you have to hide recyclerview keep the visibility of recyclerview as "gone" and to show keep visibility as "visible" like this.
Initially keep your recycler hidden in xml and by adding this line in xml
android:visibility="gone"
Thrn whenver button is clciked make your recycler appear in java like this
yourRecycler.setVisibility(View.VISIBLE);
Finally your xml should look like this
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="#+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical"
android:paddingBottom="5dp"
android:layout_alignParentBottom="true"
android:paddingTop="5dp">
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#null"
android:text="button"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/horizontalRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:animateLayoutChanges="false"
android:scrollbars="horizontal"
/>
try below steps,
First, define XML like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
>
<Button
android:id="#+id/tv1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#FFF"
android:text="hello"
android:textStyle="bold"
android:layout_weight="1"
/>
<RecycleView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:visibility="gone"
>
</RecycleView>
</LinearLayout>
Second, initially set RecycleView visibility gone.
Third, on click of Button set RecycleView visibility visible in run time.
You can use this library.
https://github.com/umano/AndroidSlidingUpPanel
In XML Put RecyclerView in its layout
<com.sothree.slidinguppanel.SlidingUpPanelLayout

Two ListView in ScrollView

I have put two listview in scrollview but i have a problem, when i put item in the first listview the second listview will be scrollable. I want that the whole area will be scrollable and not scrollview, How i do? the first scrollview is listViewEventiAggiunti the second listViewEventi.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="#+id/activity_lista__eventi"
android:paddingBottom="#dimen/padBottom"
android:paddingLeft="#dimen/padLeft"
android:paddingRight="#dimen/padRight"
android:paddingTop="#dimen/padTop"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="com.example.fra87.eudroid.activity_class.Lista_Eventi">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical">
<SearchView
android:layout_width="match_parent"
android:layout_height="50dp"
android:queryHint="Evento"
android:id="#+id/cercaEvento"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:id="#+id/linearLayoutEventi">
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Nome Evento"
android:textSize="22dip"
android:id="#+id/editText_nome_evento_composto"/>
<ListView
android:id="#+id/listViewEventiAggiunti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp" />
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:id="#+id/separatore_liste"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#android:color/darker_gray"/>
<ListView
android:id="#+id/listViewEventi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/cercaEvento"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
I want scroll entire area, i don't want scroll on listview, when i put item in listview the area increases and i scroll entire area is possible?
Ok. Since your minimum SDK version is 16, you have 2 solution for your problem.
First is use this library:
https://github.com/PaoloRotolo/ExpandableHeightListView
This library makes you able to expand your ListViews to full height and then only your ScrollView will be scrollable.
Second solution is to use NestedScrollView instead of ScrollView and then use RecyclerView instead of ListView. Then you should only disable nestedScrolling for your RecyclerView.
Both solutions will give you your desire behavior.
You can use multiple type item for listview and simplified your layout to become like this
<?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_lista__eventi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/padBottom"
android:paddingLeft="#dimen/padLeft"
android:paddingRight="#dimen/padRight"
android:paddingTop="#dimen/padTop"
tools:context="com.example.fra87.eudroid.activity_class.Lista_Eventi"
>
<SearchView
android:id="#+id/cercaEvento"
android:layout_width="match_parent"
android:layout_height="50dp"
android:queryHint="Evento"
/>
<EditText
android:id="#+id/editText_nome_evento_composto"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/cercaEvento"
android:hint="Nome Evento"
android:textSize="22dip"
/>
<View
android:id="#+id/separatore_liste"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_below="#+id/editText_nome_evento_composto"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray"
/>
<ListView
android:id="#+id/listViewEventi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/separatore_liste"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
/>
</RelativeLayout>

Android: Recycler view inside ScrollView is not working

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

Scrolling two listview inside one LinearLayout

I am trying to scroll the listview inside one Linear Layout but it is not working as i want. I am attaching one image for the more explanation.
This is my Layout
<android.support.v7.widget.CardView
android:id="#+id/card"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:clickable="false"
app:cardBackgroundColor="#android:color/white"
app:cardElevation="2dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="false">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical">
<Button
android:id="#+id/findSelected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:background="#drawable/flat_selector_green"
android:text="Next"
android:textColor="#android:color/white" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.v7.widget.CardView>
Image explanation
I know it s not the good approach to use the listview but i have to do this with this way.
Just remove the ScrollView from your xml code, Because ListView have their own Scroll doesn't require ScrollView.Then code will work as you want. Second List will be shown after showing every item of first ListView.
According to android docmentation
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
First you user card view as top parent it seem you will use it as child of list view as I guess , if my guessing is correct this not wise to use two list view as child.
Second In any case you want use two listview in same view , its recommended to separate between them with view (TextView , ... etc).
the solution
1- remove scroll as it useless.
2- add weight to your list view as wrap content in your case mean whole view.
3- recommend add view to separate between list.
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:clickable="false"
app:cardBackgroundColor="#android:color/white"
app:cardElevation="2dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/wholeview"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="2">
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<!-- recommended to add view here -->
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/findSelected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="Next"
android:textColor="#android:color/white"
/>
</LinearLayout>
</RelativeLayout>

How to change the height of ExpandableListView when group is expanded

How to change the height of ExpandableListView when group is expanded/collapsed?
I want to change the height of ExpandableListView to fit the height of its content, so that the view will not scroll inside itself.
this is the layout for main activity.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="jp.foo.android.activity.FooActivity"
tools:ignore="MergeRootFrame" />
and this is a layout for the fragment of the main activity.
<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="wrap_content"
tools:context="jp.foo.android.fragment.FooFragment"
android:background="#color/category_bg">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:id="#+id/frameLayout">
<TextView
android:text="#string/subtitle_question_category"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/subtitle_category"
android:gravity="center_vertical|center_horizontal"
android:layout_gravity="center_horizontal|top"
android:textSize="20sp" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/frameLayout"
android:background="#drawable/category_list_bg_shape"
android:layout_marginTop="0dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:minHeight="300dp">
<LinearLayout
android:id="#+id/category_list_progressbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical"
android:visibility="gone">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/category_list"
android:transcriptMode="normal">
</ExpandableListView>
</FrameLayout>
</RelativeLayout>
Below is the actual layout.
ExpandableListView will scroll inside when it has too many contents.
I want to scroll whole screen. Not only scroll view, but with header.
I solved a similar issue putting everything into a Header. I was close to solving it the traditional ways (ie. nesting layouts, weights, ...) but I felt the solution was pretty dirty, requiring overriding methods such as onGroupClick etc... to disable the ExpandableListView's scroll, while the header thing was clean and worked flawlessly for me.
So if you want to try this approach, just put an ExpandableListView alone inside your fragment, and prepare the rest to be inserted as Header.
So in your fragment a full ExpandableListView:
<ExpandableListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/category_list"
android:transcriptMode="normal">
</ExpandableListView>
Then create the layout expandable_header.xml:
<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="wrap_content"
tools:context="jp.foo.android.fragment.FooFragment"
android:background="#color/category_bg">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:id="#+id/frameLayout">
<TextView
android:text="#string/subtitle_question_category"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/subtitle_category"
android:gravity="center_vertical|center_horizontal"
android:layout_gravity="center_horizontal|top"
android:textSize="20sp" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/frameLayout"
android:background="#drawable/category_list_bg_shape"
android:layout_marginTop="0dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:minHeight="300dp">
<LinearLayout
android:id="#+id/category_list_progressbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical"
android:visibility="gone">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
And then inflate the header into the ExpandableListView:
.
.
.
View view = View.inflate(context, R.layout.expandable_header, null);
expandableList.addHeaderView(view, null, false);
.
.
.
This way the header will scroll together with the ExpandableListView, as it's inside it.
BTW, your layout has redundant elements, for example the FrameLayout that contains only a TextView. You can use only the TextView. Also the LinearLayout with the ProgressBar, if you are not using an opaque background, you could put the ProgressBar alone. The less ViewGroups you use the better the layout will perform!

Categories

Resources