首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用ViewPage滑动页面

用ViewPage滑动页面
EN

Stack Overflow用户
提问于 2014-05-18 17:25:05
回答 1查看 136关注 0票数 0

我试图用数据来填充页面的线性布局。此外,我还使用ViewPager来更改页面。每个页面都应该有自己的数据块,但是现在我得到了不滑动的线性布局(当我滑动页面时,页面就会停止),但是在其他页面之上还有另一个线性布局,它不包含数据,而是在我滑动页面时滑动。

main.xml:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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"
    tools:context=".MyActivity">
    <android.support.v4.view.ViewPager
        android:id="@+id/page"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </android.support.v4.view.ViewPager>
    <LinearLayout
        android:orientation="vertical"
        android:id="@+id/page_blocks"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        </LinearLayout>

</RelativeLayout>

table_row:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/program_frame"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="5dip">

    <TextView
        android:id="@+id/StudyName"
        />
    <TextView
        android:id="@+id/Auditorium"
        />
    <TextView
        android:id="@+id/StudyKindName"
        />
    <TextView
        android:id="@+id/LectureTitle"
        />
    <ImageView
        android:id="@+id/imageView2"
         />
</RelativeLayout>

onCreateView of ViewPage:

代码语言:javascript
运行
复制
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.table_row, null);
        framesContainer = (LinearLayout) getActivity().findViewById(R.id.page_blocks);
        for (int i = 0; i < 16; i += 4) {
            Frame frame = new Frame(getActivity());
            try {
                frame.setStudyName(s.get().get(0).Days().get(i));
                frame.setStudyKindName(s.get().get(0).Days().get(i + 1));
                frame.setAuditorium(s.get().get(0).Days().get(i + 2));
                frame.setLectureTitle(s.get().get(0).Days().get(i + 3));
                framesContainer.addView(frame);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        return view;
    }

另见图:

是否有一种方法可以隐藏空块,并使所有块在页面后滑动时滑动?

EN

回答 1

Stack Overflow用户

发布于 2014-05-24 03:50:39

您的问题是您使用的是RelativeLayouts,而且由于您没有对齐它的子元素(ViewPager和LinearLayout),所以它们是重叠的:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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"
    tools:context=".MyActivity">
    <android.support.v4.view.ViewPager
        android:id="@+id/page"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" />
    <LinearLayout
        android:orientation="vertical"
        android:id="@+id/page_blocks"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/page" >
    </LinearLayout>

这一行告诉查看器,它的位置将位于RelativeLayout的顶部:

代码语言:javascript
运行
复制
android:layout_alignParentTop="true"

这个告诉LinearLayout它的位置在查看器下面:

代码语言:javascript
运行
复制
android:layout_below="@id/page"

还有一些其他属性可以设置-> RelativeLayout

老实说,我不知道你想做什么。但是,也许您只需要摆脱RelativeLayout,转而使用LinearLayouts。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23724799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档