屏幕布局无法滚动

时间:2017-03-31 04:50:49

标签: android android-layout android-fragments android-scrollview android-tablayout

我有一个外部ScrollView,其中有一个RecyclerView和三个选项卡。每个选项卡都有一个片段,该片段使用ViewPager加载到相应的选项卡中,但外部ScrollView不会滚动我的布局。我使用嵌套的ScrollView但它也不滚动。也许我做错了什么。有没有人有建议?请与我分享。 这是我的xml代码结构

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/parent_scroll"
    android:layout_weight="1"
    android:background="@color/business_price_bg"
    android:focusableInTouchMode="false">

    <RelativeLayout
        android:id="@+id/business_detail_main_rl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/activity_main_search_top_main_ll"
            android:layout_width="match_parent"
            android:layout_height="@dimen/activity_main_search_top_main_ll_height"
            android:background="@color/location_setting_bottom_button_color"
            android:gravity="center"
            android:orientation="vertical">

        </LinearLayout>

        <RelativeLayout
            android:id="@+id/business_detail_activity_business_slider_main_rl"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_below="@+id/activity_main_search_top_main_ll">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/business_detail_activity_slider_recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="vertical" />
        </RelativeLayout>

        <TextView
            android:id="@+id/business_detail_activity_business_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/business_detail_activity_business_slider_main_rl"
            android:layout_margin="10dp"
            android:text=""
            android:textColor="@android:color/black"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/business_detail_activity_business_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/business_detail_activity_business_title"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:text=""
            android:textSize="13sp" />

        <android.support.design.widget.TabLayout
            android:id="@+id/business_detail_activity_tabslayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/business_detail_activity_business_description"
            android:background="@android:color/transparent"
            app:tabIndicatorColor="@color/pencilin_orange_color"
            app:tabIndicatorHeight="5dp"
            app:tabTextAppearance="@style/MyTabLayoutTextAppearance" />

        <android.support.v4.view.ViewPager
            android:id="@+id/business_detail_activity_viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/business_detail_activity_tabslayout"
            android:background="@android:color/white" />

    </RelativeLayout>
</ScrollView>

2 个答案:

答案 0 :(得分:0)

您违反了Android的UI标准,这就是您无法实现目标的原因。尝试坚持使用Android UI标准,并制作不太复杂的用户界面。

答案 1 :(得分:0)

  

我更改了屏幕布局结构,最后ScrollView正在运行   这是解决方案:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusableInTouchMode="true">

    <LinearLayout
        android:id="@+id/business_detail_main_rl"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:nestedScrollingEnabled="true"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:weightSum="1">

            <LinearLayout
                android:id="@+id/activity_main_search_top_main_ll"
                android:layout_width="match_parent"
                android:layout_height="@dimen/activity_main_search_top_main_ll_height"
                android:layout_weight="0."
                android:background="@color/location_setting_bottom_button_color"
                android:gravity="center"
                android:orientation="vertical">

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.45"
                android:orientation="vertical">

                <RelativeLayout
                    android:id="@+id/business_detail_activity_business_slider_main_rl"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:layout_below="@+id/activity_main_search_top_main_ll">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/business_detail_activity_slider_recycler_view"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_alignParentStart="true"
                        android:layout_alignParentTop="true"
                        android:scrollbars="vertical" />
                </RelativeLayout>

                <TextView
                    android:id="@+id/business_detail_activity_business_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/business_detail_activity_business_slider_main_rl"
                    android:layout_margin="10dp"
                    android:text=""
                    android:textColor="@android:color/black"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/business_detail_activity_business_description"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/business_detail_activity_business_title"
                    android:layout_marginBottom="10dp"
                    android:layout_marginLeft="10dp"
                    android:text=""
                    android:textSize="13sp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.2"
                android:orientation="horizontal"
                android:weightSum="3">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    android:weightSum="1">

                    <Button
                        android:id="@+id/business_preview_screen_services_btn"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.88"
                        android:background="@android:color/transparent"
                        android:text="@string/business_preview_screen_services_btn_str"
                        android:textAllCaps="false" />

                    <View
                        android:id="@+id/business_preview_screen_service_btn_seperator"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.12"
                        android:background="@color/location_setting_bottom_button_color" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    android:weightSum="1">

                    <Button
                        android:id="@+id/business_preview_screen_about_btn"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.88"
                        android:background="@android:color/transparent"
                        android:text="@string/business_preview_screen_services_btn_about_btn_str"
                        android:textAllCaps="false" />

                    <View
                        android:id="@+id/business_preview_screen_about_btn_seperator"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.13"
                        android:background="@color/light_gray_section_cell_seperator" />
                </LinearLayout>


                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    android:weightSum="1">

                    <Button
                        android:id="@+id/business_preview_screen_staff_btn"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.88"
                        android:background="@android:color/transparent"
                        android:text="@string/business_preview_screen_services_btn_staff_btn_str"
                        android:textAllCaps="false" />

                    <View
                        android:id="@+id/business_preview_screen_staff_btn_seperator"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.13"
                        android:background="@color/light_gray_section_cell_seperator" />
                </LinearLayout>
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.2"
                android:orientation="vertical">


                <FrameLayout
                    android:id="@+id/fragment_container"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                </FrameLayout>

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