开发者

Android: Floating Bar in Layout

开发者_开发技巧

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜