添加片段?

时间:2016-03-12 21:01:11

标签: java android xml string algorithm

我正在使用这个库:

https://github.com/PaoloRotolo/AppIntro

为我的应用程序创建教程。现在,我想添加一个片段作为幻灯片。我怎样才能做到这一点?我试过这个:

    addSlide(R.layout.fragment_first);

我的片段布局是fragment_first.xml,我只想添加它。我认为该参数只接受片段ID ...如何将其添加到我的片段布局xml?

enter image description here

如何将片段添加为幻灯片?

谢谢,

Ruchir

1 个答案:

答案 0 :(得分:2)

选项1

请注意,addSlide()方法会将android.support.v4.app.Fragment作为参数。

假设你有一个类似于这样的FirstFragment.java:

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class FirstFragment extends Fragment {


    public FirstFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_first, container, false);
    }

}

只需创建FirstFragment的新实例,并将其传递给addSlide()方法:

FirstFragment fragment = new FirstFragment();
addSlide(fragment);

选项2

查看自述文件:

  
      
  • 从我的example project
  • 复制SampleSlide类   
  • 使用addSlide(SampleSlide.newInstance(R.layout.your_slide_here));
  • 添加新幻灯片   

所以,对你来说就是:

addSlide(SampleSlide.newInstance(R.layout.fragment_first));