错误夸大android.support.design.widget.coordinatorlayout to View



我想在下面的布局中夸大,但它给了我一个错误。

<android.support.design.widget.CoordinatorLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="false">
      ....
</android.support.design.widget.CoordinatorLayout>

当我尝试此代码时给我错误

 LayoutInflater.from(getApplicationContext()).inflate(R.layout.fooview, null, false)

我将设置

1)AppTheme.NoActionBar activity的样式

2) 'com.android.support:design:26.+'添加了依赖项

3)和Activity通过AppCompatActivity

扩展

日志中的错误

由:android.view.inflateException引起:二进制XML文件行#14:二进制XML文件行#14:错误夸大class android.support.design.design.widget.widget.coordinator.coordinatorlayout

为您创建了样本。对我来说,这对我来说是有效的,这对您有帮助

public class MyFragment extends Fragment {
    private View rootView;
    private TextView sampleText;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.activity_sample_two,null,false);
        sampleText = rootView.findViewById(R.id.txtView);
        sampleText.setText("Hello Code Sample");
        return rootView;
    }
}

gradle依赖性:

compile 'com.android.support:design:26.0.0-alpha1'
compile 'com.android.support:appcompat-v7:26.+'

XML文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false">
    <TextView
        android:id="@+id/txtView"
        android:layout_width="wrap_content"
        android:text="Code Sample"
        android:layout_height="wrap_content" />
</android.support.design.widget.CoordinatorLayout>

对我来说没有任何错误。您必须添加依赖项。

与活动:

public class HomeActivity extends AppCompatActivity {
    private LinearLayout linearLy;
    private CoordinatorLayout coordinatorLayout;
    private TextView txtTextView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        linearLy = (LinearLayout) findViewById(R.id.linearLy);
        coordinatorLayout = (CoordinatorLayout) getLayoutInflater().inflate(R.layout.activity_sample_two, null, false);
        txtTextView = (TextView) coordinatorLayout.findViewById(R.id.txtView);
        txtTextView.setText("Hello Sample");
        linearLy.addView(coordinatorLayout);
    }
}

mainlayout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLy"
    android:orientation="vertical"
    android:background="@android:color/holo_blue_bright"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</LinearLayout>

充气活动_sample_two.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:background="@android:color/darker_gray"
    android:fitsSystemWindows="false">
    <TextView
        android:id="@+id/txtView"
        android:layout_width="wrap_content"
        android:text="Code Sample"
        android:layout_height="wrap_content" />
</android.support.design.widget.CoordinatorLayout>

让我知道是否需要更多帮助!

相关内容

  • 没有找到相关文章

最新更新