加载活动时,scrollview在中间而不是顶部开始。有办法解决吗?

时间:2017-10-19 02:08:34

标签: android

我有一个很长的滚动视图。加载活动时,滚动视图从中间而不是顶部开始(您必须向上滚动才能看到滚动视图中的第一项)。无法解决这个问题,从来没有发生过这种情况。有没有办法解决它?这是我的资源文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_upgrade_now"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_vertical_margin"
tools:context=".views.UpgradeNowActivity"
android:orientation="vertical">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true">

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


        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="4dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="5dp">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/auroracast_pro"
                    android:textAlignment="center"
                    android:textSize="14sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/get_pro"
                    android:textSize="10sp" />

                <ListView
                    android:id="@+id/lst_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:visibility="visible" />

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/purchase_now_3_99_usd"
                    android:textSize="12sp"
                    android:textStyle="bold"
                    android:visibility="gone" />
            </LinearLayout>

        </android.support.v7.widget.CardView>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:layout_marginTop="15dp"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/scroll_to_see_pro_version_features"
                android:textAlignment="center"
                android:textAllCaps="true"
                android:textColor="@color/colorPrimaryDark"
                android:textSize="10sp" />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="25dp"
                android:tint="@color/colorPrimaryDark"
                ads:srcCompat="@drawable/downarrow" />
        </LinearLayout>


        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="4dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="5dp">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/cloud_cover_and_light_pollution_maps"
                    android:textAlignment="center"
                    android:textSize="12sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/get_access"
                    android:textSize="10sp" />

                <ImageView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="5dp"
                    android:tint="@color/colorPrimaryDark"
                    ads:srcCompat="@drawable/map_icon" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="4dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="5dp">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/location_manager"
                    android:textAlignment="center"
                    android:textSize="12sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/location_manager_desc"
                    android:textSize="10sp" />

                <ImageView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="5dp"
                    android:tint="@color/colorPrimaryDark"
                    ads:srcCompat="@drawable/mappin" />

            </LinearLayout>


        </android.support.v7.widget.CardView>


        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="4dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="5dp">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/alerts_and_notifications"
                    android:textAlignment="center"
                    android:textSize="12sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/get_alerted"
                    android:textSize="10sp" />

                <ImageView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="5dp"
                    android:tint="@color/colorPrimaryDark"
                    ads:srcCompat="@drawable/alerts_icon" />

            </LinearLayout>


        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="4dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="5dp">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/_27_day_kp_forecast_chart"
                    android:textAlignment="center"
                    android:textSize="12sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/_27_day_chart_desc"
                    android:textSize="10sp" />

                <ImageView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="5dp"
                    android:tint="@color/colorPrimaryDark"
                    ads:srcCompat="@drawable/chart" />

            </LinearLayout>


        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="4dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="5dp">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/widgets"
                    android:textAlignment="center"
                    android:textSize="12sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/enable_three_widgets"
                    android:textSize="10sp" />

                <ImageView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="5dp"
                    android:tint="@color/colorPrimaryDark"
                    ads:srcCompat="@drawable/upgwidget" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="4dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="5dp">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/faster_update_frequency"
                    android:textAlignment="center"
                    android:textSize="12sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/in_the_pro_version_aurora_data_updates_more_frequently"
                    android:textSize="10sp" />

                <ImageView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="5dp"
                    android:tint="@color/colorPrimaryDark"
                    ads:srcCompat="@drawable/icon_time" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="4dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="5dp">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/priority_app_support"
                    android:textAlignment="center"
                    android:textSize="12sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/have_questions"
                    android:textSize="10sp" />

                <ImageView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="5dp"
                    android:tint="@color/colorPrimaryDark"
                    ads:srcCompat="@drawable/support_icon" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="4dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="5dp">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/and_more"
                    android:textAlignment="center"
                    android:textSize="12sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/more_features"
                    android:textSize="10sp" />

                <ImageView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="5dp"
                    android:tint="@color/colorPrimaryDark"
                    ads:srcCompat="@drawable/smile" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <ListView
            android:id="@+id/lst_view2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="visible" />

    </LinearLayout>


</ScrollView>

<FrameLayout
    android:id="@+id/ads_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/ads_margin_top"
    android:gravity="bottom"
    android:visibility="gone">


</FrameLayout>
</LinearLayout>

我尝试添加

android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"

到滚动视图属性,因为我已经在StackOverflow的其他地方读过这是它的修复方法,但它并没有实际修复它。

0 个答案:

没有答案