ListView scrollbarStyle not working properly in a Widget - android

I'm trying to do a Widget with a ListView, but I want to show the ScrollBar really in the right side, without any padding.
I want it like the gmail calendar Widget. I will show you how with pictures:
This is my Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<FrameLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:id="#+id/widgetTitle"
android:textColor="#color/colorWhite"
android:background="#drawable/widget_title_background"
android:textSize="15dp"
android:gravity="center"
android:layout_height="#dimen/widget_title_min_height"></TextView>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="0dp"
android:background="#color/colorWhite">
<ListView
android:id="#+id/widgetListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay"
tools:listitem="#layout/widget_list_item"></ListView>
</LinearLayout>
</LinearLayout>

In Listview control scrollbar default show on right side always.
Try This code ..
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listview"></ListView>

Related

Android cardview first item and last item not showing correctly

So I follow an Android tutorial from ude*y, everything works perfectly, the only problem is the first and last item of cardview not showing correctly.
I think you have to margin or padding as your requirement.
<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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
<TextView
android:id="#+id/empty_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableTop="#drawable/tryagain"
android:gravity="center"
android:visibility="gone"
android:text="#string/no_data_available" />
</RelativeLayout>
</LinearLayout>
You want see more full card view example, please following this github:
https://github.com/dharmakshetri/CardViewExample/blob/master/app/src/main/res/layout/main.xml
and full source code:
CardViewExample

Listview Upper Bounds and Lower Bounds do not interact when the user reaches the limits

My listview is in a scrollable view, when I reach the Upper bound limit or the lower bound limit the listview doesn't show the blue circle from the bounds. How can I make the layout shows it?
After adding the overScrollMode=Always still it is not working, This Layout is added in the ScrollingActivity sample provided by Android.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:overScrollMode="always"
android:fillViewport="true>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/snackBarLocation">
</android.support.design.widget.CoordinatorLayout>
<ListView
android:id="#+id/list2"
android:layout_width="match_parent"
android:layout_height="55dp"/>
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="50dp"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="50dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text"
/>
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="10dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
This is called "over-scroll".
You can change the over-scroll mode via XML:
android:overScrollMode="always"
Or via Java:
setOverScrollMode(OVER_SCROLL_ALWAYS);
See https://developer.android.com/reference/android/widget/ScrollView.html#setOverScrollMode(int) for more information.

Android Webview selection handles and menu seen through view on top - how to hide it?

I have a main Webview and a bottom sheet that shows up occasionally, overlaying it. The bottom one is also a Webview, shown green.
The problem is that if there is any selection in the main view, the selection handles and menu show through the bottom one and I want them to hide behind.
Here is the layout:
<RelativeLayout 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:id="#+id/my_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.gary.testandroid.TestActivity"
tools:showIn="#layout/activity_test">
<com.example.gary.testandroid.BrowseView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" />
<LinearLayout
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:clipToPadding="false">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lview1"
android:elevation="0dp"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight=".62"/>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bottom_view"
android:layout_alignParentBottom="true"
android:elevation="24dp"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight=".38"/>
</LinearLayout>
</RelativeLayout>

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>

Android layout_above does not work on API 21

I have a RelativeLayout that contains 3 children (LinearLayout) :
one at the top.
one at the bottom.
and one between the 2 last views.
The code i use for it is :
<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:background="#color/white"
tools:context="fr.caudoux.onlinegames.activities.GameMainFragment">
<LinearLayout
android:orientation="vertical"
android:background="#ff44f0c3"
android:layout_alignParentTop="true"
android:id="#+id/game_main_actionbar"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
<LinearLayout
android:background="#F01234"
android:orientation="vertical"
android:id="#+id/game_main_top_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/game_main_actionbar"
android:layout_above="#+id/game_main_chat_container">
</LinearLayout>
<LinearLayout
android:background="#ff2c3ff0"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:id="#id/game_main_chat_container"
android:layout_marginBottom="70dp"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
</RelativeLayout>
Since the api 21 the attribut 'android:layout_above' is not working : the second LinearLayout take all the space below the first one, and the third LinearLayout is over the second.
On api lower than 21 it works : the second part take only the space between the first and the third Linearlayout.
Does anyone known why it is not working and hos to do ?
Thanks
Change the ordering to have your top and bottom view declared before the view that is in between the two:
<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:background="#color/white"
tools:context="fr.caudoux.onlinegames.activities.GameMainFragment">
<LinearLayout
android:orientation="vertical"
android:background="#ff44f0c3"
android:layout_alignParentTop="true"
android:id="#+id/game_main_actionbar"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
<LinearLayout
android:background="#ff2c3ff0"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:id="#id/game_main_chat_container"
android:layout_marginBottom="70dp"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
<LinearLayout
android:background="#F01234"
android:orientation="vertical"
android:id="#+id/game_main_top_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/game_main_actionbar"
android:layout_above="#+id/game_main_chat_container">
</LinearLayout>
</RelativeLayout>
As mentioned, this same layout is easier to do as a LinearLayout, which specializes in stacked elements:
<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:background="#color/white"
android:orientation="vertical"
tools:context="fr.caudoux.onlinegames.activities.GameMainFragment">
<LinearLayout
android:orientation="vertical"
android:background="#ff44f0c3"
android:id="#+id/game_main_actionbar"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
<LinearLayout
android:background="#F01234"
android:orientation="vertical"
android:id="#+id/game_main_top_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:background="#ff2c3ff0"
android:orientation="vertical"
android:id="#id/game_main_chat_container"
android:layout_marginBottom="70dp"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
</LinearLayout>
Note how only the middle element (the element that needs to fill the remaining space) has a layout_weight on it. This ensures that all remaining space is allocated to that view while the other views are of fixed height.
You cannot have both above and below set in one view. Use below on second view and then below again on last view.

Categories

Resources