How to set the header and footer for linear layout in android

后端 未结 1 507
悲哀的现实
悲哀的现实 2020-12-13 15:35

Can anybody tell me how to set a fixed header and footer for relative layout and center point? I want to add scrollable and adding array of webview dynamically when I want t

相关标签:
1条回答
  • 2020-12-13 16:24
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <!-- HEADER -->
        <include android:id="@+id/top_header"
            android:layout_alignParentTop="true" layout="@layout/layout_header" />
    
    
        <!-- FOOTER -->
        <LinearLayout android:id="@+id/bottom_menu"
            android:layout_width="fill_parent" android:layout_height="wrap_content"         
            android:orientation="vertical" android:layout_alignParentBottom="true">
            <!-- menu bar -->
            <include layout="@layout/layout_footer_menu" />
        </LinearLayout>
    
        <!-- MAIN PART -->
        <LinearLayout android:orientation="vertical"
            android:layout_width="fill_parent" android:layout_height="fill_parent"
            android:layout_below="@id/top_header" android:layout_above="@id/bottom_menu"
            android:layout_weight="1"
            android:id="@+id/sub_content_view"
            android:paddingBottom="5sp" android:background="#EAEAEA">
        </LinearLayout>
    </RelativeLayout>
    

    It is better to set to MAIN PART both:

    android:layout_below="@id/top_header" android:layout_above="@id/bottom_menu"

    In your case content will be under the footer and scroll bar will be shown incorrect.

    Also you need place footer in code above content - android want see ID's (@id/bottom_menu) if it wasn't define before.

    0 讨论(0)
提交回复
热议问题