我正在创建一个滑动视图寻呼机,我下载了一个演示,我在我的项目中使用它,但问题是我的代码的这部分:
public class ViewPagerDemo extends Activity implements ViewPager.OnPageChangeListener, View.OnClickListener{
protected View view;
private ImageButton btnNext, btnFinish;
private ViewPager intro_images;
private LinearLayout pager_indicator;
private int dotsCount;
private ImageView[] dots;
private ViewPagerAdapter mAdapter;
private int[] mImageResources = {
R.mipmap.abc1,
R.mipmap.abc2,
R.mipmap.abc3,
R.mipmap.abc4,
R.mipmap.abc5
};
@Override
protected void onCreate(Bundle savedInstanceState)
{
// To make activity full screen.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setReference();
/* toolbar.setVisibility(View.GONE);*/
}
public void setReference() {
view = LayoutInflater.from(this).inflate(R.layout.playbutton,container);
intro_images = (ViewPager) view.findViewById(R.id.pager_introduction);
btnNext = (ImageButton) view.findViewById(R.id.btn_next);
btnFinish = (ImageButton) view.findViewById(R.id.btn_finish);
pager_indicator = (LinearLayout) view.findViewById(R.id.viewPagerCountDots);
btnNext.setOnClickListener(this);
btnFinish.setOnClickListener(this);
mAdapter = new ViewPagerAdapter(ViewPagerDemo.this, mImageResources);
intro_images.setAdapter(mAdapter);
intro_images.setCurrentItem(0);
intro_images.setOnPageChangeListener(this);
setUiPageViewController();
}
@override和R.layout ....容器获得一个红色下划线,此部分 intro_images.setOnPageChangeListener(this); 上有一行。 所以当我运行项目时,我得到了这个错误:
Error:(55, 40) Gradle: error: no suitable method found for inflate(int,int)
method LayoutInflater.inflate(int,ViewGroup) is not applicable
(argument mismatch; int cannot be converted to ViewGroup)
method LayoutInflater.inflate(XmlPullParser,ViewGroup) is not applicable
(argument mismatch; int cannot be converted to XmlPullParser)
这是我使用的xml文件:
<android.support.v4.view.ViewPager
android:id="@+id/pager_introduction"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:listitem="@layout/pager_item" />
<RelativeLayout
android:id="@+id/viewPagerIndicator"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
android:gravity="center">
<LinearLayout
android:id="@+id/viewPagerCountDots"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:gravity="center"
android:orientation="horizontal" />
<ImageButton
android:id="@+id/btn_next"
android:layout_width="42dip"
android:layout_height="42dip"
android:layout_alignParentRight="true"
android:layout_marginRight="15dip"
android:background="@drawable/btn_round_semitransperant"
android:src="@mipmap/ic_navigation_arrow_forward" />
<ImageButton
android:id="@+id/btn_finish"
android:layout_width="42dip"
android:layout_height="42dip"
android:layout_alignParentRight="true"
android:layout_marginRight="15dip"
android:background="@drawable/btn_round_semitransperant"
android:contentDescription="Let's start"
android:src="@mipmap/ic_navigation_check"
android:visibility="gone" />
</RelativeLayout>
答案 0 :(得分:0)
您正在使用inflate方法错误。
改为使用view = LayoutInflater.from(this).inflate(R.layout.playbutton, container, false);
。