cardview is not wrapping the content inside swipeview - android

I Want to display an listview inside an Cardview.
This is the Code I used :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/list_layout_with_fab_list_view_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp">
<ListView
android:id="#+id/list_layout_with_fab_list_view"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:divider="#null"
android:fastScrollEnabled="true"
android:listSelector="#android:color/transparent"
android:outlineProvider="none" />
</android.support.v7.widget.CardView>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
If i remove the SwipeView the CardView is wrapping the content. but i need both swipeview as well as CardView.
Is there anything i have done wrong??

You want to wrap a content inside cardview make sure that your card view height should set to height which is able to handle the content inside just give height in numbers and check weather it handles your content or not.Use this code in your layout and check if it works or not and in #dimes/fab_margin you can set the height for your cardview.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="#dimen/fab_margin"
app:cardCornerRadius="2dp"
app:cardElevation="6dp"
android:layout_alignParentBottom="true"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView">
</ListView>
</android.support.v7.widget.CardView>
</RelativeLayout>

Related

ListView inside ScrollView(Mine issue is different)

I have a Drawer layout. I have placed a ViewPager for sliding Image and Tab Layout for dots, after I want a TextView and a ListView Again a TextView and again ListView, it goes for 4 times. So, I want my whole screen to be scroll-able. Here is the issue, if I am fixing the height of ListView app, it is starting from Bottom, If I am using match parent then list view does not scroll and it act like Linear layout and anything below this doesn't shows up. If I am using wrap content in height, the list view is scroll-able but nothing shows up after list view because whole screen is not scrolling.
MainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:background="#f5f5f5"
android:id="#+id/drawer"
android:layout_height="match_parent"
tools:context="com.tollywood2bollywood.t2bliveapp.HomeActivity">
<ScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<!--ViewPager for sliding Image-->
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="270dp"
android:id="#+id/top_stories_pager">
</android.support.v4.view.ViewPager>
<!--For dots used in scrollable image-->
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:id="#+id/tab_layout"
app:tabBackground="#drawable/tab_selector"
app:tabGravity="center"
app:tabIndicatorHeight="0dp"
android:layout_height="wrap_content"/>
<!--List View Starts -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/recent_stories"
android:layout_marginTop="5dp"
android:layout_marginStart="3dp"
android:text="RECENT STORIES"/>
<ListView
android:layout_width="match_parent"
android:id="#+id/recent_stories_listview"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ENTERTAINMENT"
android:layout_marginTop="5dp"
android:layout_marginStart="3dp"/>
<ListView
android:layout_width="match_parent"
android:id="#+id/entertainment_listview"
android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>
<!--Navigation Drawer setting-->
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:itemTextColor="#color/colorPrimaryDark"
app:itemIconTint="#color/colorPrimaryDark"
app:menu="#menu/drawermenu"
android:layout_gravity="start"
android:background="#fff">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
If I am using above xml, then Enterntainment TextView and List View following is not showing. Please Help. I am making a news app.
Change the ScrollView with NestedScrollView and ListView with RecyclerView
<android.support.v4.widget.DrawerLayout 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:background="#f5f5f5"
android:id="#+id/drawer"
android:layout_height="match_parent"
tools:context="com.tollywood2bollywood.t2bliveapp.HomeActivity">
<NestedScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:focusableInTouchMode="true"
android:layout_height="match_parent">
<!--ViewPager for sliding Image-->
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="270dp"
android:id="#+id/top_stories_pager">
</android.support.v4.view.ViewPager>
<!--For dots used in scrollable image-->
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:id="#+id/tab_layout"
app:tabBackground="#drawable/tab_selector"
app:tabGravity="center"
app:tabIndicatorHeight="0dp"
android:layout_height="wrap_content"/>
<!--List View Starts -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/recent_stories"
android:layout_marginTop="5dp"
android:layout_marginStart="3dp"
android:text="RECENT STORIES"/>
<RecyclerView
android:layout_width="match_parent"
android:clipToPadding = "false"
android:paddingBottom = "50dp"
android:id="#+id/recent_stories_listview"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ENTERTAINMENT"
android:layout_marginTop="5dp"
android:layout_marginStart="3dp"/>
<RecyclerView
android:layout_width="match_parent"
android:id="#+id/entertainment_listview"
android:clipToPadding = "false"
android:paddingBottom = "50dp"
android:layout_height="match_parent"/>
</LinearLayout>
</NestedScrollView>
<!--Navigation Drawer setting-->
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:itemTextColor="#color/colorPrimaryDark"
app:itemIconTint="#color/colorPrimaryDark"
app:menu="#menu/drawermenu"
android:layout_gravity="start"
android:background="#fff">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
here is link for migrate from ListView to RecyclerView
Please use NestedScrollView instead, it is similar to ScrollView, but it will support acting as both a nested scrolling parent and child. Please check this for more information and samples.
https://inducesmile.com/android-tips/android-recyclerview-inside-nestedscrollview-example/
change your scrollview to nestedscrollview

How to focus RecyclerView top position inside NestedScrollView?

Not able t focus the recyclerview top position inside NestedScrollView.
I have the following structure of the xml file.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_alignParentTop="true"
android:id="#+id/nested_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/cv_comment_post">
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
card_view:cardCornerRadius="#dimen/_2dp">
<!-- Some Views of -->
</android.support.v7.widget.CardView>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/card_view" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
When i am notify the recyclerview adapter then it's not focus to the top of RecyclerView using below code
mRecyclerView.scrollToPosition(0);

Android: How to Display included layout and listview in one view together?

I would like to ask how can i display included layout and listview positioned under the included in onde view.
Layout:
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.TransactionsActivity">
<include
android:layout_width="fill_parent"
android:layout_height="10dp"
android:layout_alignParentTop="true"
layout="#layout/preloader" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/list"
/>
</android.support.v4.widget.SwipeRefreshLayout>
In the preview is displayed only the included layout, but lisview below is not displayed.
Many thanks for any advice.
Since SwipeRefreshLayout accept only one child. Wrap it inside LinearLayout or RelativeLayout.
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.TransactionsActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
layout="#layout/preloader"
android:layout_width="fill_parent"
android:layout_height="10dp"
android:layout_alignParentTop="true" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Best Of Luck.

NestedScrollview inside a Recycler view not scrolling

I am creating an Android program. In this program, I have a ScrollView inside of which there is a RecyclerView. I am adding data in this RecyclerView via a RecyclerViewAdapter.
For each item of the RecyclerView, there is a NestedScrollview having a single LinearLayout of vertical orientation. I am dynamically adding ImageView in this LinearLayout.
The problem is that the images are not scrolling. In very rare scenarios (by tapping so many times on screen), it got scrolled for once.
Could anybody help me on this?
Here is the code -
Parent Recycler View :-
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/id_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#color/gray3"
android:dividerHeight="5sp"
android:paddingLeft="2sp"
android:paddingTop="5sp"
android:paddingRight="2sp"/>
<com.app.sh.widget.WrappedGridView
android:id="#+id/gridView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/White"
android:numColumns="2">
</com.app.socialhand.widget.WrappedGridView>
</LinearLayout>
</ScrollView>
And the Item of the Recycler View :-
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/vScrollView"
android:layout_below="#id/iv_up"
android:layout_above="#+id/iv_down"
android:isScrollContainer="true"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/ll_123"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
I am dynamically adding the ImageViews in ll_123.
Try to use NestedScrollView instead of ScrollView or remove it. RecyclerView has own scrollview which will conflict with ScrollView.
You can try a structure like:
<ScrollView>
<NestedScrollView>
<LinearLayout>
<RecyclerView/>
</LinearLayout>
</NestedScrollView>
</ScrollView>
And ListItem layout should contain:
<NestedScrollView>
<LinearLayout/>
</NestedScrollView>
Check if this works correctly...
I got simmilar problem and this helped me:
<ScrollView
android:id="#+id/messages_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/send_panel"
android:fillViewport="true"
android:padding="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/messages"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:animateLayoutChanges="true"
android:gravity="center_horizontal|bottom"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
</ScrollView>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<-only one layout in nestade layout->
<LinearLayout
android:id="#+id/activity_edit_existing_location"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/rcl"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<-put here yr second layout code->
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

Allow user to "scroll past" ViewPager in a LinearLayout.

So I have a linear layout with two elements in it a ViewPager and a RecyclerView. Currently when the user scrolls down the ViewPager stays at the top of the page. Preferably the what would happen is that the user would scroll past the ViewPager so that the RecyclerView took up the page. How can I make this happen?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
style="#style/AppTheme"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".ListEventsActivity">
<android.support.v4.view.ViewPager
android:id="#+id/fragment_pager"
android:layout_height="300dp"
android:layout_weight="1"
android:layout_width="match_parent"/>
<android.support.v7.widget.RecyclerView
android:layout_weight="1"
android:id="#+id/user_recycler"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Use this, you need to set the height to 0dp while applying
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
style="#style/AppTheme"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".ListEventsActivity">
<android.support.v4.view.ViewPager
android:layout_weight="0.7"
android:id="#+id/fragment_pager"
android:layout_height="0dp"
android:layout_width="match_parent"/>
<android.support.v7.widget.RecyclerView
android:layout_weight="0.7"
android:id="#+id/user_recycler"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="0dp" />
</LinearLayout>

Categories

Resources