ListView inside ScrollView(Mine issue is different) - android

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

Related

How to add button to a view pager in Android Studio?

I want to add a button to a View Pager. Tried adding button, fragment, and layout without success.
I've also tried this:
Add button to ViewPager
But it didn't work.
This is my layout
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.airpal.yonatan.airpal.MainActivity_User">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/appBarLayout">
<include layout="#layout/app_bar_layout" android:id="#+id/main_page_toolbar" />
<android.support.design.widget.TabLayout
android:id="#+id/main_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabSelectedTextColor="#android:color/white"
app:tabTextColor="#android:color/white">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/main_tabPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/appBarLayout">
</android.support.v4.view.ViewPager>
</LinearLayout>
This is the screen shot, I want to add the button on the bottom of the page.
Thanks.
You can Wrap this LinearLayout in the Relative layout. If you don't want to change the Linear layout to RelativeLayout. Here is the modified layout XML and It will display Button the Bottom Right. You can modify layout_alignParentRight to left, center depend on your need.
<?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">
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.airpal.yonatan.airpal.MainActivity_User">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/appBarLayout">
<include layout="#layout/app_bar_layout" android:id="#+id/main_page_toolbar" />
<android.support.design.widget.TabLayout
android:id="#+id/main_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabSelectedTextColor="#android:color/white"
app:tabTextColor="#android:color/white">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/main_tabPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/appBarLayout">
</android.support.v4.view.ViewPager>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
Try using RelativeLayout for the root view and use :
android:layout_alignParentBottom="true"
With LinearLayout at root view is not possible. Also, instead of RelativeLayout, ConstraintLayout is a good alternative.

Add imageView to coordinatorLayout

Here is my coordinator layout. Everything is ok, I can see everything.
But I can't see the ImageView. In code I am initializing ImageView correctly and have an object. I need Image view in center of screen.
If I change ImageView to button I see button in center of screen, but if I change to something other I canĀ“t seen that element.
Please how Can I add ImageView to coordinatorLayout?
This code is in coordinatorlayout.
Thank you.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ImageView
android:id="#+id/status_btn"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:background="#color/red" />
<Button
android:id="#+id/delete_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Smazat"
android:visibility="gone" />
<include
layout="#layout/panel_camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<!--height a width se nastavuje dynamicky-->
<LinearLayout
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<RelativeLayout
android:id="#+id/bottom_sheet_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/header_vg"
android:layout_width="match_parent"
android:layout_height="#dimen/vision_bottom_sheet_header_height"
android:layout_alignParentTop="true"
android:background="#color/gray_header_vision"
android:gravity="center">
<TextView
android:id="#+id/header_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="#color/white"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/vision_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/header_vg"
android:background="#color/white"
android:scrollbars="vertical"
android:visibility="gone" />
<include
android:id="#+id/empty_vg"
layout="#layout/panel_vision_tutorial"
android:layout_width="match_parent"
android:layout_height="#dimen/vision_bottom_sheet_item_height"
android:layout_below="#+id/header_vg" />
</RelativeLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Here is my panel_camera_preview:
<my_package.CameraSourcePreview
android:id="#+id/camera_preview"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray">
<my_package.GraphicOverlay
android:id="#+id/face_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</my_package.CameraSourcePreview>
CoordinatorLayout is a FrameLayout, thus the last View in order overlays the previous ones. Then Imageview results not visible because it is covered by your panel_camera_preview, while Button results visible, but only if is running on Lollipop or greater, cause its default elevation (2dp).

Can't place Floating Action Button (FAB) between header and items in DrawerLayout using RecyclerView

I can't get the Floating Action Button (FAB) to appear in the correct position. I want it to appear between the header and the first item in my nav drawer.
Currently, I've got it to appear in the bottom right corner of the header and NOT on top of the line between the 1st and 2nd elements (1st element = header & 2nd element = first item in recyclerview).
My app is using the following appcompat items:
appcompat-v7:23.0.0
recyclerview-v7:23.0.0
design:23.0.0
I'm using a nav drawer but I can't use the NavigationView because I need to customize the item entries and not load a simple menu.
As you know, the drawer is really not 2 different controls. The header is actually the '0' element in the RecyclerView. I don't know if this makes a difference.
Here is my current xml for the header/"0 view in RecyclerView":
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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="#dimen/navdrawer_image_height">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/navDrawerHeaderView"
android:layout_width="match_parent"
android:layout_height="#dimen/navdrawer_image_height">
<ImageView
android:id="#+id/navdrawer_image"
android:layout_width="wrap_content"
android:layout_height="#dimen/navdrawer_image_height"
android:contentDescription="#string/cd_navdrawer_image"
android:scaleType="centerCrop"
android:src="#drawable/bg_material_design" />
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/app_image"
android:layout_width="#dimen/navdrawer_user_picture_size"
android:layout_height="#dimen/navdrawer_user_picture_size"
android:src="#drawable/ic_launcher"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
app:border_width="2dp"
app:border_color="#FF000000"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/appNameTextView"
android:text="App Name"
android:textStyle="bold"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:layout_alignParentBottom="true"
android:textColor="#android:color/white"/>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="#drawable/button_account"
app:layout_anchor="#id/navDrawerHeaderView"
app:layout_anchorGravity="bottom|right|end"
app:elevation="4dp"/>
</android.support.design.widget.CoordinatorLayout>
I think I might have the FAB in the wrong location/file. Here is the xml for the drawer.
<?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"
android:id="#+id/drawerLayout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true">
<!-- Content layout -->
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/tool_bar"/>
<FrameLayout
android:id="#+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/init_background">
</FrameLayout>
</LinearLayout>
<!-- Pages -->
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#ffffff"
android:scrollbars="vertical"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.DrawerLayout>
HELP!!!!!
example drawer fragment layout containing your existing RecyclerView:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="200dp">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00"
android:id="#+id/header"/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:scrollbars="vertical"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_anchor="#id/appbar"
app:layout_anchorGravity="bottom|right|end"
android:layout_margin="5dp"
android:clickable="true"/>
</android.support.design.widget.CoordinatorLayout>

Floating Action Buttons over Drawer Menu

I have added 2 floating action buttons to my activity. The problem is that I also have a drawer menu and when I open it my floating buttons remain visible.
This is how my XML file looks like:
<android.support.design.widget.CoordinatorLayout
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.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"
></include>
<LinearLayout
android:id="#+id/viewA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="#FF8845"
android:orientation="horizontal"/>
<LinearLayout
android:id="#+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:background="#AF3800"
android:orientation="horizontal">
<ListView
android:id="#+id/listView5"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="270dp"></ListView>
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyclerView"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#ffffff"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.DrawerLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/button_add_new_friend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="#drawable/ic_add_friend"
app:layout_anchor="#id/viewA"
app:layout_anchorGravity="bottom|right|end"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/button_user_photos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="100dp"
android:clickable="true"
android:src="#drawable/ic_user_photos"
app:layout_anchor="#id/viewA"
app:layout_anchorGravity="bottom|right|end"/>
</android.support.design.widget.CoordinatorLayout>
And this is how they look like:
Any ideas how I can solve this problem?
Set visibility of buttons GONE or INVISIBLE in onDrawerOpened(View view) listener.
Move floating buttons declaration in XML to the top of CoordinatorLayout container (before the DrawerLayout declaration). Android draws views from top to bottom.
UPD.
As suggested by #JohanShogun, elevation might be the key. FABs probably have default elevation value higher than you have in your DrawerLayout. Try to override it with lower value and if it won't help, have a look at this answer.

Using Floating Action Button With Tabs

I am using floating action button with slidingtablayout, but when i use fab in fragments every tab will have its own fab, and transition looks bad like this video from google design
http://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B6Okdz75tqQsNVRkV3FZMktvMWc/components-buttons-fab-behavior_06_xhdpi_009.webm
When i use fab in the viewpager it shrinks fragments like in the link
https://drive.google.com/file/d/0By6vpKpg_w4tcEJQUUlRazd0VEk/view?usp=sharing
Here is my code activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<com.smooth.www.smooth.SlidingTabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="2dp"
android:background="#color/ColorPrimary"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
and one of my tabs
<android.support.design.widget.CoordinatorLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#f0f0f0"
>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/tab_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v7.widget.RecyclerView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/main_recycler"
/>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="normal"
android:id="#+id/main_fab"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:transitionName="#string/fab_transition_name"
android:src="#drawable/fab_image"
app:layout_anchor="#id/main_recycler"
app:layout_anchorGravity="bottom|right|end"
/>
</android.support.design.widget.CoordinatorLayout>
what can i do to for transitions to look good??
Looks like you ar using a LinearLayout or something, instead of RelativeLayout. Can you post code snippets?

Categories

Resources