java - 由于未找到 View 错误, ScrollView 被隐藏

标签 java android xml android-fragments android-toolbar

我刚刚实现了一个 ScrollView ,但在部署过程中,我收到此错误,我不知道为什么+不知道我的代码出了什么问题。

No view found for id 0x7f0e006c (com.blah.blah:id/container) for fragment FragmentAbout

fragment_about.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbarThumbVertical="@drawable/light_scrollbar">
        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:contentDescription="@string/app_name"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="center_horizontal"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:src="@drawable/ic_launcher"
                />

            <TextView
                android:id="@+id/textView1"
                android:text="@string/app_name"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                style="@android:style/TextAppearance.Large"/>

            <TextView
                android:id="@+id/textView3"
                android:text="@string/version_no."
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                style="@android:style/TextAppearance.Small"/>

            <TextView
                android:id="@+id/textView4"
                android:text="@string/copyright_info"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:paddingBottom="10dp"
                style="@android:style/TextAppearance.Small"/>

            <TextView
                android:id="@+id/textView5"
                android:text="@string/developer_info"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingBottom="10dp"
                style="@android:style/TextAppearance.Small"/>
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

activity_about.xml

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

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/actionBar"
        android:elevation="4dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:contentInsetEnd="0dp"
        app:contentInsetStart="16dp" >
    </android.support.v7.widget.Toolbar>

    <LinearLayout
        android:id="@+id/container"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</FrameLayout>

AboutActivity.java

public class AboutActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);

        Toolbar toolbar = (Toolbar) findViewById(R.id.actionBar);
        if (toolbar != null) {
            setSupportActionBar(toolbar);
            toolbar.setBackgroundColor(Color.parseColor("#212121"));
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowHomeEnabled(false);
        }

        getSupportFragmentManager().beginTransaction()
                .replace(R.id.container, new FragmentAbout())
                .commit();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_about, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            final Intent intent = NavUtils.getParentActivityIntent(this);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            NavUtils.navigateUpTo(this, intent);
            return true;
        }

        int id = item.getItemId();
        if (id == R.id.action_0) {
            new AlertDialog.Builder(this)
                    .setTitle("Hello World")
                    .setMessage("Hello World")
                    .show();
        }
        if (id == R.id.action_1) {
            new AlertDialog.Builder(this)
                    .setTitle("Hello World")
                    .setMessage("Hello World")
                    .show();
        }
        return super.onOptionsItemSelected(item);
    }
}

最佳答案

您正在将内容 View 设置为 fragment 的布局。那不是你想要的。您想将其设置为 Activity 的布局,R.id.activity_about

关于java - 由于未找到 View 错误, ScrollView 被隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31527079/

相关文章:

java - Bck2Brwsr 与 JavaFX 一起?

java - 如何更改匿名类中的实例变量

android - 将用于面部匹配的图像发送到 Android 上的 AWS Rekognition 时出错

android - 如何从 iOS/Android 应用程序中运行 Vue.js?

java - 使用java获取XML文件中的所有标签

java - 如何用 java 中的字节数组编写 WAV 文件?

c# - 如何从 token 创建 PlusService 的实例

java - findViewByID() 不起作用。我应该怎么办?

c# - 更改 WCF Web Api HttpContext 响应

java - 得到奇怪的输出,如 "Values@7d5b6e"而不是某些特定的字符串