膨胀包含片段的布局(将抛出异常)

时间:2015-09-07 17:25:34

标签: java android android-layout android-fragments android-inflate

我试图为包含内部片段的RecyclerView的布局进行充气。我的布局有一些标签,第一次一切正常,但是如果我在标签之间滑动,则会抛出异常。

我的布局要夸大(只会膨胀一次)

<fragment
        android:id="@+id/map_view"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="260dp"
        android:layout_marginTop="15dp" />

错误

  

android.view.InflateException:二进制XML文件行#133:错误   膨胀类片段

注意:我无法使用MapView,如果这是解决方案,请举例说明如何使用它。

堆栈跟踪是:

09-07 00:48:31.404  13234-13234/com.collect_up.c_up E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.collect_up.c_up, PID: 13234
    android.view.InflateException: Binary XML file line #133: Error inflating class fragment
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at com.collect_up.c_up.adapters.ShopInfoAdapter.onCreateViewHolder(ShopInfoAdapter.java:63)
            at com.collect_up.c_up.adapters.ShopInfoAdapter.onCreateViewHolder(ShopInfoAdapter.java:43)
            at com.marshalchen.ultimaterecyclerview.UltimateViewAdapter.onCreateViewHolder(UltimateViewAdapter.java:61)
            at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5116)
            at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4416)
            at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4326)
            at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1955)
            at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1364)
            at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1327)
            at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:556)
            at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2713)
            at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3011)
            at android.view.View.layout(View.java:15671)
            at android.view.ViewGroup.layout(ViewGroup.java:5038)
            at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:581)
            at android.view.View.layout(View.java:15671)
            at android.view.ViewGroup.layout(ViewGroup.java:5038)
            at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
            at android.view.View.layout(View.java:15671)
            at android.view.ViewGroup.layout(ViewGroup.java:5038)
            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
            at android.view.View.layout(View.java:15671)
            at android.view.ViewGroup.layout(ViewGroup.java:5038)
            at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1627)
            at android.view.View.layout(View.java:15671)
            at android.view.ViewGroup.layout(ViewGroup.java:5038)
            at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1034)
            at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:744)
            at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
            at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1180)
            at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:757)
            at android.view.View.layout(View.java:15671)
            at android.view.ViewGroup.layout(ViewGroup.java:5038)
            at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
            at android.view.View.layout(View.java:15671)
            at android.view.ViewGroup.layout(ViewGroup.java:5038)
            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
            at android.view.View.layout(View.java:15671)
            at android.view.ViewGroup.layout(ViewGroup.java:5038)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
            at android.view.View.layout(View.java:15671)
            at android.view.ViewGroup.layout(ViewGroup.java:5038)
            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
            at android.view.View.layout(View.java:15671)
            at android.view.ViewGroup.layout(ViewGroup.java:5038)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
            at android

注意:我使用ButterKnife注入视图,我使用这样的片段:

((SupportMapFragment) ((AppCompatActivity) context).getSupportFragmentManager()
                                                                   .findFragmentById(R.id.map_view))
                        .getMapAsync(new OnMapReadyCallback() {
                            @Override
                            public void onMapReady(GoogleMap googleMap) {
                                mGoogleMap = googleMap;
                                mGoogleMap.getUiSettings().setZoomControlsEnabled(false);
                                mGoogleMap.getUiSettings().setMyLocationButtonEnabled(true);
                                mGoogleMap.getUiSettings().setCompassEnabled(false);
                                mGoogleMap.getUiSettings().setScrollGesturesEnabled(false);
                                mGoogleMap.getUiSettings().setMapToolbarEnabled(false);

                                new Location(context).getLocation(new LocationCallback() {
                                    @Override
                                    public void onLocationFound(final LatLng latLngs) {
                                        mGoogleMap.addMarker(new MarkerOptions().position(latLngs)
                                                                                .title(context.getString(R.string.you_are_here)));
                                        mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLngs, context
                                                .getResources()
                                                .getInteger(R.integer.map_zoom_far)));

                                        mGoogleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
                                            @Override
                                            public void onMapClick(LatLng latLng) {
                                                if (itemListener != null) {
                                                    itemListener.onMapClick(latLngs);
                                                }
                                            }
                                        });
                                    }
                                });
                            }
                        });

0 个答案:

没有答案