Android ScrollView example
ScrollView
It is definitely a very important view that various teaching materials and tutorials have more or less missed. If the composition of this interface is very irregular, and the length in the correct direction is not enough, it must be used Scrollview
. Because it ListView
deals with the content of rules. As for a simple example, I will discover how to use Scrollview.
There are a few news pages with pictures. Under the pictures, you can click the button to learn more, there are titles, and finally all the news content. If the content is warriors, the list view does not seem to be the best choice, but generally The layout, for example LinearLayout
, RelativeLayout
or FrameLayout
the like layout is also useless. In the end, only the ScrollView
problem can be solved.
ScrollView
It is such a special layout. When ScrollView
the content is larger than its own size, it ScrollView
will automatically add a scroll bar and slide vertically.
-
ScrollView
There can only be one direct child view of. If you want to use a very complicated view structure, like the news mentioned in the previous question, you must put these views in a standard layout, such asLinearLayout
,RelativeLayout
etc. - You can use
layout_width
andlayout_height
give theScrollView
specified size. -
ScrollView
Only batch process combinations of irregular views that require scrolling. Large-scale list data display can be usedListView
,GridView
orRecyclerView
. -
ScrollView
AndListView
there will be a conflict nested slide such use. Don't use it unless you have to. -
ScrollView
Only supports vertical sliding, horizontal sliding useHorizontalScrollView
. -
ScrollView
Theandroid:fillViewport
attribute of defines whether the content can be stretched to fill the viewport. You can call methodssetFillViewport(boolean)
to achieve the same effect.
Android ScrollView example
layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:padding="10dp"
tools:context="demo.scrollviewdemo.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="@drawable/nba" />
<Button
android:id="@+id/knowMoreButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/know_more" />
<TextView
android:id="@+id/titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/contentTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/content"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</ScrollView>
Continuously updating...
Article reference learning address: https://www.jianshu.com/p/ddd295a06d17