滚动时,页脚重叠菜单项

时间:2017-09-19 11:18:06

标签: android android-layout android-studio scrollview android-linearlayout

我有标题,菜单和页脚的活动。 如果我将屏幕的方向更改为水平以便滚动显示,则页脚将与最后一个菜单项(按钮6)重叠。如果我单击页脚,则会触发Button6的处理程序。

如何使页脚不与菜单项重叠,我可以看到所有菜单项?

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
tools:context="com.test.test.MainMenuActivity">

<LinearLayout
    android:background="@color/colorMainWhite"
    style="@style/root_layout">

    <!--- Header-->
    <include layout="@layout/content_header"/>
    <include layout="@layout/content_subheader"/>

    <!--- Menu-->
    <ScrollView
        android:id="@+id/myview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical">
    <LinearLayout
        android:id="@+id/InfoLayout"
        android:paddingTop="@dimen/size_15px"
        android:orientation="vertical"
        style="@style/los_lo_info_item">
        <TextView
            android:id="@+id/tvNL1"
            tools:text="test"
            style="@style/tvs_lo_text_32_bold_ellipsized"/>
        <TextView
            android:id="@+id/tvNL2"
            tools:text="test"
            style="@style/tvs_lo_text_26_ellipsized"/>
    </LinearLayout>


    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical">
        <LinearLayout
            android:id="@+id/button1"
            style="@style/los_lo_mainmenu_item">
            <ImageView
                style="@style/icon_default_size_center"
                android:src="@drawable/icon_1"/>
            <TextView
                style="@style/tvs_lo_text_mainmenu_button"
                android:text="@string/title_item_1"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/button2"
            style="@style/los_lo_mainmenu_item">
            <ImageView
                style="@style/icon_default_size_center"
                android:src="@drawable/icon_2"/>
            <TextView
                style="@style/tvs_lo_text_mainmenu_button"
                android:text="@string/title_item_2"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/button3"
            style="@style/los_lo_mainmenu_item">
            <ImageView
                style="@style/icon_default_size_center"
                android:src="@drawable/icon_3"/>
            <TextView
                style="@style/tvs_lo_text_mainmenu_button"
                android:text="@string/title_item_3"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/button4"
            style="@style/los_lo_mainmenu_item">
            <ImageView
                style="@style/icon_default_size_center"
                android:src="@drawable/icon_4"/>
            <TextView
                style="@style/tvs_lo_text_mainmenu_button"
                android:text="@string/title_item_4"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/button5"
            style="@style/los_lo_mainmenu_item">
            <ImageView
                style="@style/icon_default_size_center"
                android:src="@drawable/icon_5"/>
            <TextView
                style="@style/tvs_lo_text_mainmenu_button"
                android:text="@string/title_item_5"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/button6"
            style="@style/los_lo_mainmenu_item">
            <ImageView
                style="@style/icon_default_size_center"
                android:src="@drawable/icon_6"/>
            <TextView
                style="@style/tvs_lo_text_mainmenu_button"
                android:text="@string/title_item_6"/>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
    </ScrollView>
</LinearLayout>
<!--- Footer-->
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:gravity="bottom">
    <LinearLayout
        android:paddingTop="@dimen/size_20px"
        android:paddingBottom="@dimen/size_20px"
        android:background="@color/colorBgLightGrey"
        android:layout_width="match_parent"
        android:gravity="center_horizontal"
        android:layout_height="wrap_content">
        <ImageView
            android:src="@drawable/icon_logos_ips"
            style="@style/ips_icons_style"/>
    </LinearLayout>
</LinearLayout>

新:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
tools:context="com.test.test.MainMenuActivity">

<RelativeLayout
    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <include
        android:id="@+id/layout_content_header"
        layout="@layout/content_header"/>
    <include
        android:id="@+id/layout_content_subheader"
        android:layout_below="@id/layout_content_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/content_subheader"/>

    <!--- Menu-->
    <ScrollView
        android:id="@+id/myview"
        android:layout_width="match_parent"
        android:layout_below="@id/layout_content_subheader"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical">
            <LinearLayout
                android:id="@+id/merchantInfoLayout"
                android:paddingTop="@dimen/size_15px"
                android:orientation="vertical"
                style="@style/los_lo_merchant_info_item">
                <TextView
                    android:id="@+id/tvNL1"
                    tools:text="test"
                    style="@style/tvs_lo_text_32_bold_ellipsized"/>
                <TextView
                    android:id="@+id/tvNL2"
                    tools:text="test"
                    style="@style/tvs_lo_text_26_ellipsized"/>
            </LinearLayout>


            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="vertical">
                <LinearLayout
                    android:id="@+id/button1"
                    style="@style/los_lo_mainmenu_item">
                    <ImageView
                        style="@style/icon_default_size_center"
                        android:src="@drawable/icon_1"/>
                    <TextView
                        style="@style/tvs_lo_text_mainmenu_button"
                        android:text="@string/title_item_1"/>
                </LinearLayout>
                <LinearLayout
                    android:id="@+id/button2"
                    style="@style/los_lo_mainmenu_item">
                    <ImageView
                        style="@style/icon_default_size_center"
                        android:src="@drawable/icon_2"/>
                    <TextView
                        style="@style/tvs_lo_text_mainmenu_button"
                        android:text="@string/title_item_2"/>
                </LinearLayout>
                <LinearLayout
                    android:id="@+id/button3"
                    style="@style/los_lo_mainmenu_item">
                    <ImageView
                        style="@style/icon_default_size_center"
                        android:src="@drawable/icon_3"/>
                    <TextView
                        style="@style/tvs_lo_text_mainmenu_button"
                        android:text="@string/title_item_3"/>
                </LinearLayout>
                <LinearLayout
                    android:id="@+id/button4"
                    style="@style/los_lo_mainmenu_item">
                    <ImageView
                        style="@style/icon_default_size_center"
                        android:src="@drawable/icon_4"/>
                    <TextView
                        style="@style/tvs_lo_text_mainmenu_button"
                        android:text="@string/title_item_4"/>
                </LinearLayout>
                <LinearLayout
                    android:id="@+id/button5"
                    style="@style/los_lo_mainmenu_item">
                    <ImageView
                        style="@style/icon_default_size_center"
                        android:src="@drawable/icon_5"/>
                    <TextView
                        style="@style/tvs_lo_text_mainmenu_button"
                        android:text="@string/title_item_5"/>
                </LinearLayout>
                <LinearLayout
                    android:id="@+id/button6"
                    style="@style/los_lo_mainmenu_item">
                    <ImageView
                        style="@style/icon_default_size_center"
                        android:src="@drawable/icon_6"/>
                    <TextView
                        style="@style/tvs_lo_text_mainmenu_button"
                        android:text="@string/title_item_6"/>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:gravity="bottom">
        <LinearLayout
            android:paddingTop="@dimen/size_20px"
            android:paddingBottom="@dimen/size_20px"
            android:background="@color/colorBgLightGrey"
            android:layout_width="match_parent"
            android:gravity="center_horizontal"
            android:layout_height="wrap_content">
            <ImageView
                android:src="@drawable/icon_logos_ips"
                style="@style/ips_icons_style"/>
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

1 个答案:

答案 0 :(得分:2)

将这些内容添加到android:layout_weight="1" 将起作用

android:orientation="vertical"

使用android:layout_weight并将LinearLayout设为ScrollView,将页脚保持在<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"> <LinearLayout android:id="@+id/mainLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <!--- Header--> <include layout="@layout/content_header" /> <!--- Menu--> <ScrollView android:id="@+id/myview" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical"> <LinearLayout android:id="@+id/InfoLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:paddingTop="15dp"> <TextView android:id="@+id/tvNL1" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:text="test" /> <TextView android:id="@+id/tvNL2" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:text="test" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical"> <LinearLayout android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_action_hardware_keyboard_arrow_left" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="title_item_1" /> </LinearLayout> <LinearLayout android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_action_hardware_keyboard_arrow_left" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="title_item_2" /> </LinearLayout> <LinearLayout android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_action_hardware_keyboard_arrow_left" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="title_item_3" /> </LinearLayout> <LinearLayout android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_action_hardware_keyboard_arrow_left" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="title_item_4" /> </LinearLayout> <LinearLayout android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_action_hardware_keyboard_arrow_left" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="title_item_5" /> </LinearLayout> <LinearLayout android:id="@+id/button6" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_action_hardware_keyboard_arrow_left" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="title_item_6" /> </LinearLayout> <LinearLayout android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_action_hardware_keyboard_arrow_left" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="title_item_7" /> </LinearLayout> <LinearLayout android:id="@+id/button8" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_action_hardware_keyboard_arrow_left" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="title_item_8" /> </LinearLayout> </LinearLayout> </LinearLayout> </ScrollView> <!--- Footer--> <include layout="@layout/content_subheader" /> </LinearLayout> </android.support.design.widget.CoordinatorLayout>

以下

检查布局:

content_subheader.xml

这是您的<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="bottom" android:orientation="horizontal"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorAccent" android:gravity="center_horizontal" android:paddingBottom="20px" android:paddingTop="20px"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_action_hardware_keyboard_arrow_left" /> </LinearLayout> </LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true">

    <RelativeLayout
        android:id="@+id/mainLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <!--- Header-->
        <include
            android:id="@+id/header"
            layout="@layout/header_layout" />

        <!--- Menu-->
        <ScrollView
            android:id="@+id/myview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/header"
            android:layout_weight="1"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="vertical">

                <LinearLayout
                    android:id="@+id/InfoLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:paddingTop="15dp">

                    <TextView
                        android:id="@+id/tvNL1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        tools:text="test" />

                    <TextView
                        android:id="@+id/tvNL2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        tools:text="test" />
                </LinearLayout>


                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:orientation="vertical">

                    <LinearLayout
                        android:id="@+id/button1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/ic_action_hardware_keyboard_arrow_left" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="title_item_1" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/button2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/ic_action_hardware_keyboard_arrow_left" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="title_item_2" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/button3"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/ic_action_hardware_keyboard_arrow_left" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="title_item_3" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/button4"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/ic_action_hardware_keyboard_arrow_left" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="title_item_4" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/button5"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/ic_action_hardware_keyboard_arrow_left" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="title_item_5" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/button6"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/ic_action_hardware_keyboard_arrow_left" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="title_item_6" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/button7"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/ic_action_hardware_keyboard_arrow_left" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="title_item_7" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/button8"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/ic_action_hardware_keyboard_arrow_left" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="title_item_8" />
                    </LinearLayout>

                </LinearLayout>
            </LinearLayout>
        </ScrollView>

        <!--- Footer-->
        <include layout="@layout/footer_layout" />
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

注意:我已从布局中删除了所有样式,因为我没有其属性

新:

$('#content p').hide();

$('.tabs li a').click(function(){
  $('#' + $(this).data('id')).slideDown().siblings('p').slideUp();
});

$('.tabs li a').first().trigger('click');