MainActivity:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab2 = (FloatingActionButton) findViewById(R.id.developer);
fab2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CFAlertDialog.Builder builder = new CFAlertDialog.Builder( MainActivity.this)
.setDialogStyle(CFAlertDialog.CFAlertStyle.ALERT)
.setTitle("Developer Info")
.setMessage ( "This Application is Developed By :\nPriyansh MIshra\nB.Tech CSE \nAUMP Gwalior" )
.addButton( "OK", -1, -1, CFAlertDialog.CFAlertActionStyle.POSITIVE,
CFAlertDialog.CFAlertActionAlignment.CENTER, ( dialog, which) -> {
dialog.dismiss();
});
builder.show();
}
});
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.info);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CFAlertDialog.Builder builder = new CFAlertDialog.Builder( MainActivity.this)
.setDialogStyle(CFAlertDialog.CFAlertStyle.ALERT)
.setTitle("Info\n"+"App v1.0\n")
.setMessage ( "Amity YouthFest \nPresents Chroma 2K18" )
.addButton( "OK", -1, -1, CFAlertDialog.CFAlertActionStyle.POSITIVE,
CFAlertDialog.CFAlertActionAlignment.CENTER, ( dialog, which) -> {
dialog.dismiss();
});
builder.show();
}
});
FloatingActionButton fab1 = (FloatingActionButton) findViewById(R.id.contactus);
fab1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendEmail();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
displaySelectedScreen(R.id.nav_home);
}
private void sendEmail ( ) {
String[] TO = {""};
String[] CC = {""};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData( Uri.parse( "mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"priyansh.mishra19@gmail.com"});
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Groomauto:Enquiry");
emailIntent.putExtra(Intent.EXTRA_TEXT, " ");
try {
startActivity(Intent.createChooser(emailIntent,"Send mail..."));
finish();
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText( MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
public boolean onNavigationItemSelected(MenuItem item) {
displaySelectedScreen(item.getItemId());
return true;
}
private void displaySelectedScreen(int itemId) {
//creating fragment object
Fragment fragment = null;
switch (itemId) {
case R.id.nav_home:
fragment = new FragmentHome ();
break;
case R.id.nav_about:
fragment = new FragmentAbout ();
break;
case R.id.nav_events:
fragment = new FragmentEvents ();
break;
case R.id.nav_gallery:
fragment = new FragmentGallery ();
break;
case R.id.nav_winners:
fragment = new FragmentWinners();
break;
case R.id.nav_login:
fragment = new FragmentRegister();
break;
}
//replacing the fragment
if (fragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(content_frame, fragment);
ft.commit();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
}
}
XML代码:
<ScrollView
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@drawable/fundo"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/fadingTextView1"
android:layout_height="wrap_content">
<com.tomer.fadingtextview.FadingTextView
android:layout_width="match_parent"
android:layout_height="100dp"
app:texts="@array/examples"
app:timeout="500"
android:padding="10dp"
android:textSize="18sp"
android:fontFamily="casual"
android:textStyle="bold"
android:textAlignment="center"
android:textColor="@color/colorAccent"
android:id="@+id/fadingTextView"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/layout1"
android:layout_below="@id/fadingTextView1"
android:layout_margin="0dp">
<com.daimajia.slider.library.SliderLayout
android:id="@+id/slider"
android:layout_width="fill_parent"
android:layout_height="320dp"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:id="@+id/title"
android:textStyle="bold"
android:textAlignment="center"
android:layout_below="@id/layout1"
android:text="Reviews and Words Of Wisdom"
android:textColor="@color/colorAccent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_below="@id/title"
>
<HorizontalScrollView
android:layout_width="match_parent"
android:scrollbars="horizontal"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="280dp"
app:cardCornerRadius="20dp"
android:layout_margin="10dp"
android:layout_height="300dp"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:paddingTop="10dp"
android:layout_height="wrap_content">
<com.mikhaellopez.circularimageview.CircularImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:src="@drawable/vc"
app:civ_border_color="#e6e1e1"
app:civ_border_width="6dp"
android:layout_marginLeft="40dp"
android:layout_gravity="center_horizontal"
app:civ_shadow="true"
app:civ_shadow_radius="20"
app:civ_shadow_color="#8BC34A"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textColor="#1d3bd2"
android:textSize="20sp"
android:textStyle="normal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Passion and commitment to make our university on top is visible among students, dosed with sense of responsibility within."
android:textAlignment="center"
android:textColor="#000"
android:textSize="15sp"
android:textStyle="normal" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="280dp"
app:cardCornerRadius="20dp"
android:layout_margin="10dp"
android:layout_height="300dp"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:paddingTop="10dp"
android:layout_height="wrap_content">
<com.mikhaellopez.circularimageview.CircularImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:src="@drawable/provc"
app:civ_border_color="#e6e1e1"
app:civ_border_width="6dp"
android:layout_marginLeft="40dp"
android:layout_gravity="center_horizontal"
app:civ_shadow="true"
app:civ_shadow_radius="20"
app:civ_shadow_color="#8BC34A"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textColor="#1d3bd2"
android:textSize="20sp"
android:textStyle="normal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Kudos to all the wonderful efforts the students are putting into developing young talent for this great university."
android:textAlignment="center"
android:textColor="#000"
android:textSize="15sp"
android:textStyle="normal" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="280dp"
app:cardCornerRadius="20dp"
android:layout_margin="10dp"
android:layout_height="300dp"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:paddingTop="10dp"
android:layout_height="wrap_content">
<com.mikhaellopez.circularimageview.CircularImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:src="@drawable/hoi"
app:civ_border_color="#e6e1e1"
app:civ_border_width="6dp"
android:layout_marginLeft="40dp"
android:layout_gravity="center_horizontal"
app:civ_shadow="true"
app:civ_shadow_radius="20"
app:civ_shadow_color="#8BC34A"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textColor="#1d3bd2"
android:textSize="20sp"
android:textStyle="normal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Wonderful organization of symposium by our students. I wish them all the best for their future endeavours."
android:textAlignment="center"
android:textColor="#000"
android:textSize="15sp"
android:textStyle="normal" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="280dp"
app:cardCornerRadius="20dp"
android:layout_margin="10dp"
android:layout_height="300dp"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:paddingTop="10dp"
android:layout_height="wrap_content">
<com.mikhaellopez.circularimageview.CircularImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:src="@drawable/nasirkhan"
app:civ_border_color="#e6e1e1"
app:civ_border_width="6dp"
android:layout_marginLeft="40dp"
android:layout_gravity="center_horizontal"
app:civ_shadow="true"
app:civ_shadow_radius="20"
app:civ_shadow_color="#8BC34A"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textColor="#1d3bd2"
android:textSize="20sp"
android:textStyle="normal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textColor="#000"
android:textSize="15sp"
android:textStyle="normal" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</RelativeLayout>
</ScrollView>
片段类
@SuppressLint("ValidFragment")
public class FragmentHome extends android.support.v4.app.Fragment implements BaseSliderView.OnSliderClickListener, ViewPagerEx.OnPageChangeListener{
SliderLayout sliderLayout;
HashMap<String,String> Hash_file_maps ;
@Nullable
@Override
public View onCreateView (@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState ) {
return inflater.inflate( R.layout.fragment_home, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
String[] texts = {"YouthFest Of The Year \n We Hold A Brand \n Let's Make A Dream Come True ",
"Most Awaited YouthFest Chroma \n AUMP" ,
" Grab The Opputunity \n Light Your Night \n DJ NIght"};
FadingTextView FTV = (FadingTextView)view.findViewById( R.id.fadingTextView);
FTV.setTexts(texts);
Hash_file_maps = new HashMap<String, String>();
sliderLayout = (SliderLayout)view.findViewById(R.id.slider);
Hash_file_maps.put("Android Workshop", "http://www.i3indyatechnologies.com/img/android-application-development.jpg");
Hash_file_maps.put("Ludo", "http://amityaump.com/android%20images/ludo.jpg");
Hash_file_maps.put("Python Workshop", "https://aeccodingclub.files.wordpress.com/2017/01/python-workshop-poster-viveks.jpg?w=1024");
Hash_file_maps.put("Treasure Hunt", "http://amityaump.com/android%20images/treasure%20hunt.jpg");
Hash_file_maps.put("Solo Dance", "http://amityaump.com/android%20images/solo%20dance.jpg");
for(String name : Hash_file_maps.keySet()){
TextSliderView textSliderView = new TextSliderView(FragmentHome.this.getActivity());
textSliderView
.description(name)
.image(Hash_file_maps.get(name))
.setScaleType(BaseSliderView.ScaleType.Fit)
.setOnSliderClickListener(this);
textSliderView.bundle(new Bundle());
textSliderView.getBundle()
.putString("extra",name);
sliderLayout.addSlider(textSliderView);
}
sliderLayout.setPresetTransformer(SliderLayout.Transformer.Accordion);
sliderLayout.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
sliderLayout.setCustomAnimation(new DescriptionAnimation());
sliderLayout.setDuration(3000);
sliderLayout.addOnPageChangeListener(this);
}
@Override
public void onStop() {
sliderLayout.stopAutoCycle();
super.onStop();
}
@Override
public void onSliderClick(BaseSliderView slider) {
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
@Override
public void onPageSelected(int position) {
Log.d("Slider Demo", "Page Changed: " + position);
}
@Override
public void onPageScrollStateChanged(int state) {}
}
错误:java.lang.RuntimeException:无法启动活动 ComponentInfo {com.darkweb.android.chroma2018 / com.darkweb.android.chroma2018.MainActivity}: android.view.InflateException:二进制XML文件行#0:错误 膨胀班 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 在android.app.ActivityThread.access $ 800(ActivityThread.java:151) 在 android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1321) 在android.os.Handler.dispatchMessage(Handler.java:110) 在android.os.Looper.loop(Looper.java:193) 在android.app.ActivityThread.main(ActivityThread.java:5292) at java.lang.reflect.Method.invokeNative(Native Method) 在java.lang.reflect.Method.invoke(Method.java:515) 在 com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:824) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) at dalvik.system.NativeStart.main(Native Method) 引起:android.view.InflateException:二进制XML文件行#0: 膨胀类时出错 在android.view.LayoutInflater.createView(LayoutInflater.java:620) 在 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 在android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) 在 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) 在android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 在android.view.LayoutInflater.inflate(LayoutInflater.java:492) 在android.view.LayoutInflater.inflate(LayoutInflater.java:397) 在 com.darkweb.android.chroma2018.FragmentHome.onCreateView(FragmentHome.java:36)
答案 0 :(得分:0)
我认为你的XML父母/孩子搞砸了。您从Scrollview开始,但以线性布局结束。你应该有一个父布局,并在里面做其他一切。我猜测看到XLMS在你复制并粘贴了一些内容后两次声明,我猜测它搞砸了你的树。