Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to automatically display vertical scrollbar?

Tags:

android

layout

I created a user form which fits the window in vertical orientation. When the user slides the keyboard the form doesn't fit the screen (horizontal orientation). I tried to add the scrollbar but it is not visible.

I would appreciate if anyone could show how to modify the following layout file in order to display scrollbar when the orientation is set to horizontal.

Thanks!

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" 
    android:orientation="vertical" 
    android:scrollbars="vertical" 
    android:scrollbarAlwaysDrawVerticalTrack="true">
        ...
    </LinearLayout>
like image 700
Niko Gamulin Avatar asked Sep 30 '09 12:09

Niko Gamulin


People also ask

How do I make my vertical scrollbar always visible?

Windows and Linux always show you the scroll bars, but if you're on Mac you have to change a setting to get them to show. Go to System Preferences, then General and toggle “Show scroll bars” to “Always”.

How do I keep my vertical scroll bar?

On the left side of the Ease of Access screen, click the “Display” option. On the right, turn off the “Automatically Hide Scroll Bars In Windows” toggle to make sure your scrollbars don't disappear anymore.

Can scroll vertically Android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In this above code, we have declare Linear layout as parent and added Vertical Scroll view.

How to use vertical scroll view in Android Studio?

It is used to scroll child views in a vertical direction. This example demonstrates how to use Vertical Scroll view. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.

How can I always show the scrollbar in my ScrollView?

The scrollbar in my scrollview is only visible when I start scrolling. How can I always show it? As of now the best way is to use android:fadeScrollbars="false" in xml which is equivalent to ScrollView.setScrollbarFadingEnabled (false); in java code. Setting the android:scrollbarFadeDuration="0" will do the trick.

What is the use of horizontalscrollview in Android?

ScrollView is used to scroll the child elements of palette inside ScrollView. Android supports vertical scroll view as default scroll view. Vertical ScrollView scrolls elements vertically. Android uses HorizontalScrollView for horizontal ScrollView. Let's implement simple example of vertical ScrollView.

How to make textview scrollable on Android?

Making TextView scrollable on Android you need to use a android:scrollbars properties of your TextView in your layout’s XML file. Then use the below code in the Activity file. This method will enable scrolling on TextView.


2 Answers

Remove the scrollbar attributes and wrap the whole thing in a ScrollView.

like image 87
CommonsWare Avatar answered Oct 15 '22 00:10

CommonsWare


You can't replace the LinearLayout with ScrollView because ScrollView only supports one Direct Child and LinearLayout may have many. So the only option i see is to wrap

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:overScrollMode="always" 
        android:isScrollContainer="true" 
        android:scrollbarAlwaysDrawVerticalTrack="true" 
        android:scrollbarStyle="outsideInset" 
        android:scrollbars="vertical">

You can pick a variety of other attributes. These worked for my implementation. It is the first container in my layout.LinearLayout is a child of this container. Other UI elements are part of LinearLayout

Hope this helps... Alex

like image 22
Alex Vishnev Avatar answered Oct 14 '22 23:10

Alex Vishnev