【问题标题】:How to center view on screen while ViewPager has page bigger than screen?当 ViewPager 的页面大于屏幕时,如何在屏幕上居中显示视图?
【发布时间】:2016-01-10 23:22:20
【问题描述】:

我有一个ViewPager(标准),它放在ScrollView中(以防页面比屏幕大。在每个页面上我都有一个Spinner(进度条)用于显示数据加载。 Spinner 以页面为中心。

但是当页面比屏幕大时,Spinner 不会在屏幕上居中,因为它在页面上居中,Spinner 在屏幕底部(甚至隐藏在屏幕下方)。

那么如何设置Spinner 居中在屏幕上(而不是在页面上)?

更新: 微调器必须在 viewpager 中的页面上,因为每个页面都必须加载一些数据表单服务器,并且微调器指示每个页面的加载过程分开。

这是寻呼机的位置:

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

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"/>

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

这是一个页面布局:

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

    <GridView
        android:id="@+id/my_gird"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="72dp"/>

    <TextView
        android:id="@+id/test_text"
        android:visibility="gone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="!!!!!!" />

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        />

</RelativeLayout>

【问题讨论】:

    标签: android android-layout android-viewpager centering


    【解决方案1】:

    您可以将微调器添加到 ViewPager 活动中

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >
    
            <ScrollView 
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
                <LinearLayout 
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@android:color/white"
                    android:orientation="horizontal">
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"/>
    
                    <android.support.v4.view.ViewPager
                        android:id="@+id/viewpager"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@android:color/white" />
                </LinearLayout>
            </ScrollView>
             <ProgressBar
                android:id="@+id/progressBar"
                style="?android:attr/progressBarStyleLarge"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
            /> 
        </RealativeLayout>
    

    希望有帮助

    【讨论】:

    • 它不能解决我的问题,因为我必须在视图寻呼机中访问进度条表单页面。
    • @LunaVulpo 你不能为此提供回调吗?
    • @Shark 也许我可以,但最后我通过以编程方式测量屏幕尺寸并将进度条设置在正确的位置来解决我的问题。
    猜你喜欢
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 2016-12-08
    相关资源
    最近更新 更多