在活动中查看寻呼机

时间:2013-04-22 11:21:01

标签: android android-viewpager

我想用viewpager滑动活动,而不是通过android中的手势监听器。 我能够在图像视图上添加视图寻呼机,但不能在活动上添加,所以请帮助我... 提前谢谢!

3 个答案:

答案 0 :(得分:3)

在寻呼机中为每个视图使用片段。

onCreate()的{​​{1}}方法中编写以下代码。

FragmentActivity

样本片段定义:

List<Fragment> fragments = new Vector<Fragment>();

//for each fragment you want to add to the pager
Bundle page = new Bundle();
page.putString("url", url);
fragments.add(Fragment.instantiate(this,MyFragment.class.getName(),page));

//after adding all the fragments write the below lines

this.mPagerAdapter  = new PagerAdapter(super.getSupportFragmentManager(), fragments);

mPager.setAdapter(this.mPagerAdapter);

编辑(添加):FragmentPagerAdapter

public class MyFragment extends Fragment {


public static MyFragment newInstance(String imageUrl) {

final MyFragment mf = new MyFragment ();

    final Bundle args = new Bundle();
    args.putString("somedata", "somedata");
    mf.setArguments(args);

    return mf;
}

public MyFragment() {}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String data = getArguments().getString("somedata");
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // Inflate and locate the main ImageView
    final View v = inflater.inflate(R.layout.my_fragment_view, container, false);
    //... 
    return v;
}

答案 1 :(得分:1)

像这样使用overridePendingTransition

startActivity(YourNewActivity);
overridePendingTransition(R.anim.right_to_left,
                            R.anim.left_to_right);

<强> right_to_left.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="300"
        android:fromXDelta="100%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="0%" />

</set>

<强> left_to_right.xml

<translate
    android:duration="300"
    android:fromXDelta="0%"
    android:fromYDelta="0%"
    android:toXDelta="-100%"
    android:toYDelta="0%" />

答案 2 :(得分:1)

ViewPager仅保留views,而activity可选择支持fragments,其他activity内的activity被正式折旧。