我有以下MainActivity.java
import java.util.Date;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.Toast;
import com.mydomain.myappname.CardoApplication;
import com.mydomain.myappname.R;
import com.mydomain.myappname.adapters.HomeTabsPagerAdapter;
import com.mydomain.myappname.extensions.SlidingTabLayout;
public class MainActivity extends AppCompatActivity {
private ViewPager mViewPager;
private HomeTabsPagerAdapter mPageAdapter;
private Toolbar mToolbar;
private SlidingTabLayout mTabs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setViewsClassMembers();
setSupportActionBar(mToolbar);
mPageAdapter = new HomeTabsPagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mPageAdapter);
// Assiging the Sliding Tab Layout View
mTabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width
// Setting Custom Color for the Scroll bar indicator of the Tab View
mTabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.tabsScrollColor);
}
});
// Setting the ViewPager For the SlidingTabsLayout
mTabs.setViewPager(mViewPager);
}
private void setViewsClassMembers() {
mViewPager = (ViewPager) findViewById(R.id.pager);
mToolbar = (Toolbar) findViewById(R.id.tool_bar);
mTabs = (SlidingTabLayout) findViewById(R.id.tabs);
}
}
还有这个ActiveFragment.java代码
package com.xplete.cardo.fragments;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.mydomain.myappname.R;
public class ActiveFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_active, container, false);
return v;
}
}
这是我的fragment_active.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_active"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="You Are In Tab active"
android:id="@+id/textView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</fragment>
当我运行它时,我收到以下错误消息:
10-25 13:49:09.014:E / AndroidRuntime(8699): android.view.InflateException:二进制XML文件行#2:错误 膨胀类片段
我做错了什么?
答案 0 :(得分:1)
你在XML布局中做错了。 group by resortsn
将其更改为<fragment>...</fragment>
,如Layout
<RelativeLayout> ...</RelativeLayout>