i want to load more data in a fragment when scroll View reaches end..
My layout has Scroll view with a Linear Layout i am creating Tex view and button dynamically..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="#drawable/background">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtv"
android:textColor="#ffffff"
android:gravity="center"
android:background="#drawable/booktitle" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollViewid"
android:layout_below="#+id/txtv">
<LinearLayout
android:id="#+id/linearlayoutid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</RelativeLayout>
you need to use either a recyclerview or listview for that, scrollview is not meant for that refer this tutorial http://developer.android.com/training/material/lists-cards.html and run this sample app to understand it better http://developer.android.com/samples/RecyclerView/index.html since recyclerview is new i recommend you use that
Related
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
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
Hi i am new for android in my app i am adding Frame-layout inside LinearLayout but Frame-Layout and it's inside fields are not adding
my code is below please help me some one
main.xml:-
<?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">
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent'"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight ="1"
android:layout_height="wrap_content"
android:background="#android:color/holo_red_dark"
android:text="something" />
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#android:color/holo_red_light"/>
</FrameLayout>
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/frame" />
</LinearLayout>
I think you misunderstand the purpose of FrameLayout.
http://developer.android.com/reference/android/widget/FrameLayout.html
FrameLayout is designed to block out an area on the screen to display
a single item. Generally, FrameLayout should be used to hold a single
child view, because it can be difficult to organize child views in a
way that's scalable to different screen sizes without the children
overlapping each other.
You are trying to put two items inside of it. I would suggest removing the FrameLayout. You have no need of it.
<?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">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button" />
</FrameLayout>
</LinearLayout>
This works for displaying a single button, but there's no point in having it there.
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
I have a listview that holds expandable cards. Each card is 2 frame views, one for the un-expanded view and one for the expanded view. In the expanded view I have another listview - that doesn't scroll. Can anyone tell me why? Here's some code:
First listview:
<LinearLayout
android:background="#null"
android:id="#+id/contentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/groups_listview"
android:layout_width="match_parent"
android:divider="#null"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
2nd listview (Expanded Card Content):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
xmlns:fontawesometext="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_expandablelistitem_card_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/corners_white_transparent"
android:orientation="vertical" >
<ListView
android:id="#+id/friendsInGroupListview"
android:layout_width="match_parent"
android:layout_height="200dp"
android:divider="#null" >
</ListView>
</LinearLayout>
Expandable card:
<?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="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants"
android:padding="16dp" >
<FrameLayout
android:id="#+id/activity_expandablelistitem_card_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</FrameLayout>
<FrameLayout
android:id="#+id/activity_expandablelistitem_card_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp" >
</FrameLayout>
</LinearLayout>
I'd never use wrap_content in the layout_height nor layout_width, it causes performance issues, as you may read here. Also setting a static width/height is not a good idea as it may lead to layout issues in several devices.
Said that, I always define my ListViews like this:
<ListView
android:id="#+id/who_list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical">
</ListView>
Setting your layout_weight within a LinearLayout with just this view inside it, you make yourself sure that ListView will have a good layout rendering and it will enable scrolling when needed.