当前位置: 首页 > 知识库问答 >
问题:

布局膨胀错误片段

孟胤
2023-03-14

主要活动:

    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);
}

}

<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.filflateException:二进制XML文件行#0:错误inflating类在Android.app.activitythread.performLaunchActivity(ActivityThread.java:2338)在Android.app.activityThread.handleLaunchActivity(ActivityThread.java:2390)在)在Android.os.handler.dispatchMessage(handler.java:110)在Android.os.looper.loop(looper.java:193)在Android.app.activitythread.main(activitythread.java:5292)在java.lang.reflect.Method.invokenative(原生方法)在java.lang.reflect.Method.invoke(Method.java:515)在com.android.internal.os.zygoteinit$methodandargscaller.run nativeStart.main(本机方法)由:droid.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.createView(layoutinflater.java:492)在com.darkweb.android.chroma2018.fragenthome.oncreateView(fragenthome.java:36)

共有1个答案

傅振濂
2023-03-14

我认为您的XML父级/子级搞砸了。您从滚动视图开始,但以线性布局结束。您应该有一个父布局,并在内部做其他所有事情。我猜测,通过看到XLMS在顶部声明了两次,您复制并粘贴了一些东西,我猜测它扰乱了您的树。

 类似资料:
  • 我试图将我的GLSurfaceView设置在xml布局以及其他UI元素上,并不断获得错误inflating类com.vi.cubo01。MyGLSurfaceView在LogCat. 以下是java代码: 以及xml:

  • 我在自定义控件中膨胀MvxImageView时遇到问题。 从我所做的研究中,我发现了几个嫌疑人 > < li >我是否应该将“如果”添加到“什么”中?(我看到这是关于android地图视图膨胀错误。 < li> 我创建的用户控件是不是都错了?我看到了一个使用SetContentView()而不是inflate的建议,因为它通过mvvmcross机制传递indlate请求,但在自定义视图中没有这样的

  • 问题内容: 我正在尝试创建一个扩展的自定义视图。这是我的班级定义文件 : 这是在我的ghostviewscreen.xml中: 现在,我在活动中进行了: 当被调用时,抛出一个异常: 谁能告诉我为什么会出现此错误?谢谢。 问题答案: 我想我弄清楚了为什么这没用。当我应该为两个参数“ Context,AttributeSet”的情况提供构造函数时,我只为一个参数“ context”的情况提供了构造函数

  • 我想创建一个应用程序,其中NavigationView和Bottom Navigation可以互相工作,但在输出中,我在“Run”中得到了下一个字符串。 .

  • 问题内容: 您好,我是android dev和admob的新手。我正在尝试制作一个带有按钮,几个页面和底部的admob的简单测试应用程序。一切正常,直到我尝试实施admob。这是我的代码: HelloAndroid.java: main.xml: 您好android清单: logcat输出: 我正在使用GoogleAdMobAdsSdkAndroid-6.0.0。再次,我对此非常陌生,我尝试在多个

  • 问题内容: 错误日志: 10-26 12:22:33.144 26926-26926 /?E / AndroidRuntime:致命例外:主进程:ksmk.sahip.com.ecom,PID:26926 java.lang.RuntimeException:无法启动活动ComponentInfo {ksmk.sahip.com.ecom / ksmk.sahip.com.ecom.MainAct