java - 工具栏小部件与 ScrollView 重叠

标签 java android xml android-fragments android-toolbar

我刚刚实现了 ScrollView 和 Android 工具栏小部件,但在部署期间,由于某种原因,工具栏似乎与 ScrollView 重叠。

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">

            <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"/>
        </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();
    }
}

最佳答案

因为在你的activity_about.xml中,你使用了FrameLayout。 FrameLayout 对 subview 不承担任何责任。使用 LinearLayout 而不是 FrameLayout。

activity_about.xml

<?xml version="1.0" encoding="utf-8"?>
  <LinearLayout 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"/>

</LinearLayout>

关于java - 工具栏小部件与 ScrollView 重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31527371/

相关文章:

java - JButton 被删除后会在 JPanel 中留下痕迹吗?

java - 重构java中常见的静态方法

android - 使用 Gpt 声明依赖项时,Gpt 和 Gradle 中的实现有什么区别?

android - 使用 Easytracker 的谷歌分析中的未捕获异常

java - 如何从 ldap DirContextOperations 获取 memberOf 属性

Java获取CPU核心使用率百分比

android - 等待数据库完成插入数据,然后再继续下一个 Android Activity

php - XML 解析 - 缺少节点

c# - 属性未被 XmlSerializer 序列化

.net - 如何在没有不必要的空格和换行符的情况下序列化 XML? (。网)