Does anyone know how to add a floating bar that will stay at the top of a layout page, even when a user is scrolling through the contents of that layout?
Just add that bar at the top of your layout, and wrap the rest of the content with a ScrollView
. For example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Header -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your header"/>
<!-- rest of your layout -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Foo"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Bar"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Baz"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="etc"/>
</ScrollView>
</LinearLayout>
That way, the wrapped part of your view will be scrollable while the header will remain in the same site.
精彩评论