Scrollview for Android controls (scrollbarstyle)

Source: Internet
Author: User

Scrollview. When the content exceeds the entire screen or container, use scrollview.

In addition, scrollview can have only one direct sub-element.

The usage of scrollview is very simple. Here we mainly talk about the usage of scrollbar in scrollview.


1. scrollbar of a normal style (default style), as shown in:




2. Let's take a look at the effect of comparison:


The implementation is as follows:

Layout:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track"    android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"    android:scrollbarSize="12dip">                 ......</ScrollView>

Scrollbar_vertical_track.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android">    <gradient android:startColor="#505050" android:endColor="#C0C0C0"            android:angle="0"/>    <corners android:radius="0dp" /></shape>


Scrollbar_vertical_thumb.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android">    <gradient android:startColor="#3333FF" android:endColor="#8080FF"            android:angle="0"/>    <corners android:radius="6dp" /></shape>

3. the style of the scrollbar in scrollview

This attribute can be configured through an XML file, such as Android: scrollbarstyle = "insideinset"

You can also use the Java code to configure: findviewbyid (R. Id. view3). setscrollbarstyle (view. scrollbars_inside_inset );


You can set four attributes:

1> outsideinset: This scrollbar is displayed on the edge of the view and adds the view padding. If possible, this scrollbar only overwrites the view background.

2> outsideoverlay: The scrollbar is displayed on the edge of the view. The view padding is not added, and the scrollbar is semi-transparent.

3> insideinset: The scrollbar is displayed in the padding area, and the padding Area of the control is added. The scrollbar does not overlap with the view content.

4> insideoverlay: The scrollbar is displayed in the content area, and the padding Area of the control is not added. The scrollbar overwrites the View content with a translucent style.


The following is an example:

<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: Orientation = "vertical">

<Linearlayout
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: Orientation = "horizontal">

<Scrollview
Android: layout_width = "100dip"
Android: layout_height = "120dip"
Android: Background = "#00ff00"
Android: paddingright = "12dip"
Android: scrollbarstyle = "outsideinset">

<Textview
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: Background = "#60aa60"
Android: text = "@ string/scrollbar_3_text"
Android: textcolor = "#000000" type = "codeph" text = "/codeph"/>
</Scrollview>

<Scrollview
Android: Id = "@ + ID/view3"
Android: layout_width = "100dip"
Android: layout_height = "120dip"
Android: Background = "#00ff00"
Android: paddingright = "12dip"
Android: scrollbarstyle = "outsideoverlay">

<Textview
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: Background = "#60aa60"
Android: text = "@ string/scrollbar_3_text"
Android: textcolor = "#000000" type = "codeph" text = "/codeph"/>
</Scrollview>
</Linearlayout>

<Linearlayout
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: Orientation = "horizontal">

<Scrollview
Android: Id = "@ + ID/view4"
Android: layout_width = "100dip"
Android: layout_height = "120dip"
Android: Background = "@ Android: drawable/edit_text"
Android: scrollbarstyle = "insideinset">

<Textview
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/scrollbar_3_text"
Android: textcolor = "#000000" type = "codeph" text = "/codeph"/>
</Scrollview>

<Scrollview
Android: Id = "@ + ID/view5"
Android: layout_width = "100dip"
Android: layout_height = "120dip"
Android: Background = "@ Android: drawable/edit_text"
Android: scrollbarstyle = "insideoverlay">

<Textview
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/scrollbar_3_text"
Android: textcolor = "#000000" type = "codeph" text = "/codeph"/>
</Scrollview>
</Linearlayout>

</Linearlayout>

Result of scrollview:





However, there are no differences between the padding areas of insideinset and insideoverlay in two or three graphs. The layout above is slightly modified,

So, see (the last two scrollviews ):




Thank you! Reprinted please indicate the source: http://blog.csdn.net/johnny901114/article/details/7869047


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.