android - LayoutInflate Exception with ViewPager -
java.lang.runtimeexception: unable start activity componentinfo{urlinq.android.com.edu_chat_lollipop/urlinq.android.com.edu_chat.loginactivity}: android.view.inflateexception: binary xml file line #10: binary xml file line #10: error inflating class android.support.v4.view.viewpager
still getting message after reinstalling android studio. not sure going on here got message after updating minsdk version.
i have user using same files , application able run. fragment runs viewpager. have red exclamation mark next background on viewpager defined in activity.
private viewpager mviewpager; private pageradapter mcustompageradapter; private imagebutton signupbtntoggle; private imagebutton loginbtntoggle; private imagebutton loginbtn; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override /** * load login_main.xml layout. * in addition, load viewpager. */ public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { //initialize viewpager object. view v = inflater.inflate(r.layout.login_main, container, false); mviewpager = (viewpager) v.findviewbyid(r.id.loginpager); mviewpager.setadapter(new loginadapter(getactivity().getsupportfragmentmanager())); final layerdrawable background = (layerdrawable) mviewpager.getbackground(); background.getdrawable(0).setalpha(0); //lowest drawable background.getdrawable(1).setalpha(0); background.getdrawable(2).setalpha(1); //outermost drawable. mviewpager.setpagetransformer(true, new viewpager.pagetransformer() { @override public void transformpage(view view, float position) { int index = (integer) view.gettag(); drawable currentdrawableinlayerdrawable; currentdrawableinlayerdrawable = background.getdrawable(index); // change visibility of each of fragment layers when swiping left , right. if (position <= -1 || position >= 1) { currentdrawableinlayerdrawable.setalpha(0); } else if (position == 0) { currentdrawableinlayerdrawable.setalpha(255); } else { currentdrawableinlayerdrawable.setalpha((int) (255 - math.abs(position * 255))); } } }); return v; }
login_drawable.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <bitmap android:id="@+id/idofbg3" android:gravity="fill" android:src="@drawable/welcome" /> </item> <item> <bitmap android:id="@+id/idofbg2" android:gravity="fill" android:src="@drawable/welcome2" /> </item> <item> <bitmap android:id="@+id/idofbg1" android:gravity="fill" android:src="@drawable/welcome3" /> </item> </layer-list>
build.gradle
apply plugin: 'com.android.application' android { compilesdkversion 23 buildtoolsversion '23.0.1' defaultconfig { applicationid "urlinq.android.com.edu_chat_lollipop" minsdkversion 22 targetsdkversion 23 versioncode 1 versionname "1.0" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } repositories { maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } } dependencies { compile 'com.loopj.android:android-async-http:1.4.9' } } dependencies { compile filetree(dir: 'libs', include: ['*.jar']) testcompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.android.support:design:23.0.1' }
login_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" android:layout_alignparentleft="true" android:layout_alignparentright="true" android:layout_alignparenttop="true"> <android.support.v4.view.viewpager android:id="@+id/loginpager" android:layout_width="match_parent" android:layout_height="340dp" android:background = "@drawable/login_drawable" android:layout_alignparentend="true" android:layout_alignparentstart="true" /> <fragment android:layout_width="match_parent" android:layout_height="285dp" android:name="urlinq.android.com.edu_chat.signupfragment" android:id="@+id/fragment" android:layout_alignparentstart="true" android:layout_alignparentend="true" tools:layout="@layout/combined_login" android:layout_alignparentbottom="true" /> <imageview android:layout_width="150dp" android:layout_height="65dp" android:id="@+id/educhatlogo" android:background="@drawable/chatlogo" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="20dp" /> </relativelayout>
try add dependencies
compile 'com.android.support:support-v4:23.0.1'
Comments
Post a Comment