用刷卡的的ViewPage页面 [英] Swiping the pages with ViewPage

查看:153
本文介绍了用刷卡的的ViewPage页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用的LinearLayout块通过数据来填充页面。另外我使用ViewPager改变页面。每个页面应该有它自己的数据块,但现在我越来越不刷卡出linearlayouts(块停滞不前时,我刷卡页),但还有另外一个的LinearLayout正上方,这并不constist数据,但其他的人当我刷卡页面滑动。

I'm trying to fill the page by blocks of linearlayout by data. Also I'm using ViewPager for changing pages. Every page should have its own data blocks, but now I'm getting linearlayouts that doesn't swipes out (blocks stand still when I'm swiping pages) but there is another linearlayout right above the other ones that doesn't constist data but sliding when I swipe pages.

main.xml中:

<?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:

<?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>

的ViewPage的onCreateView:

@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;
    }

另外图片:

Also pic:

有没有一种方法来隐藏空块,使所有块页面后刷卡滑动时?

Is there a way to hide the empty block and make all blocks slide after the page when swiping?

推荐答案

您的问题是,你正在使用RelativeLayouts,既然你不调整其子元素(ViewPager和的LinearLayout),他们是重叠的:

Your problem is that you are using RelativeLayouts, and since you are not aligning its children elements(ViewPager and LinearLayout), they are overlapping:

<?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的顶部的viewpager:

This line tells the viewpager that its position is going to be at the top of the RelativeLayout:

android:layout_alignParentTop="true"

和这一个告诉的LinearLayout它的位置是viewpager如下:

And this one tells the LinearLayout its position is below the viewpager:

android:layout_below="@id/page"

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

There are some other properties that can be set --> RelativeLayout

说实话,我不知道你正在尝试做的。但是,也许你只需要摆脱的RelativeLayout和使用LinearLayouts代替。

To be honest, I'm not sure what you are trying to do. But maybe you just need to get rid of the RelativeLayout and use LinearLayouts instead.

这篇关于用刷卡的的ViewPage页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆