【发布时间】:2016-04-21 08:43:08
【问题描述】:
查看层次结构
<LinearLayout>
<Toolbar>..
</Toolbar>
<FrameLayout>
<CoordinatorLayout>..
<FrameLayout>
</FrameLayout>
</CoordinatorLayout>
</FrameLayout>
</LinearLayout>
想要摆脱那个深蓝色条带。不知道为什么 Co-ordinatorLayout 将此视图附加在顶部。我尝试用 LinearLayout 替换它,这导致了预期的结果。无法弄清楚为什么以及什么视图显示为蓝色暗条。
toolbar_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/white"
app:title="DISCOVER"
app:titleTextAppearance="@style/TextAppearance.MyApp.Widget.ActionBar.Title" />
<View
style="@style/Divider"
android:background="@color/grey_light" />
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
</FrameLayout>
</LinearLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.discover.MainActivity">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.discover.MainActivity"
tools:showIn="@layout/activity_main"
android:layout_margin="0dp"
android:background="#11a2cb"></FrameLayout>
</android.support.design.widget.CoordinatorLayout>
BaseActivity.java
@Override
public void setContentView(int layoutResID) {
super.setContentView(R.layout.toolbar_layout);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mContentlayout = (FrameLayout) findViewById(R.id.content);
setSupportActionBar(mToolbar);
getLayoutInflater().inflate(layoutResID, mContentlayout);
}
在 MainActivity 我使用setContentView(R.layout.activity_main)
【问题讨论】:
-
将
CoordinatorLayout中的padding设置为0,将margin0 设置为FrameLayout。 -
我特意为 coordinatorlayout 和 framelayout 添加了边距,以提供清晰的视图层次结构。虽然尝试上述尺寸不会影响任何东西,但空间。
-
您能否发布完整的 XML 不仅是层次结构。
-
你没有尝试进入设计模式并点击它吗?这可以帮助您识别对象是什么
-
它不显示在设计“预览”模式中。只有当我运行应用程序时,这个视图才会显示出来。。
标签: android android-layout android-coordinatorlayout