【问题标题】:RelativeLayout is not drawing correctly with coordinator layout androidRelativeLayout 未使用协调器布局 android 正确绘制
【发布时间】:2016-06-26 20:21:09
【问题描述】:

我编写了一个简单的片段,其中包含几个文本视图和一个按钮,都在一个相对布局中。

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

    <TextView
        android:id="@+id/tuto_title"
        style="?android:textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:padding="20dp"
        android:text="@string/tutorial_title"/>

    <TextView
        android:id="@+id/tuto_msg"
        style="?android:textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/tuto_title"
        android:padding="20dp"
        android:text="@string/tutorial_txt"/>

    <Button
        android:id="@+id/nextBtn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_margin="15dp"
        android:text="@string/next"/>

</RelativeLayout>

这个片段在 StudioDesigner 上显示很好,但是在执行代码时,标题不见了

活动布局是

<?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"
android:id="@+id/coordinatorLayout"
tools:context="com.crocodil.software.a1ccalc.A1CActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"/>

</android.support.design.widget.AppBarLayout>


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:id="@+id/fragment_container"
             android:layout_width="match_parent"
             android:layout_height="match_parent" />

它看起来就像片段在放置工具栏之前计算其可用空间...

这是我在设计器中看到的屏幕

感谢任何提示

【问题讨论】:

  • 这当然是正确的。然而,设计师以不同的方式显示 AVD 或真实设备的屏幕,这很烦人。它使调试变得更加困难。

标签: android android-layout android-fragments coordinator-layout


【解决方案1】:

取这个属性

app:layout_behavior="@string/appbar_scrolling_view_behavior"

并将其放在 FrameLayout fragment_container 上。

【讨论】:

    【解决方案2】:

    问题是FrameLayout在工具栏后面,在有工具栏的coordinator布局中添加视图的主要方法是设置margin或将app:layout_behavior="@string/appbar_scrolling_view_behavior"添加到Framelayout

    <?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"
    android:id="@+id/coordinatorLayout"
    tools:context="com.crocodil.software.a1ccalc.A1CActivity">
    
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 android:id="@+id/fragment_container"
                 android:layout_width="match_parent"
                 android:layout_marginTop="?attr/actionBarSize"
                 android:layout_height="match_parent" />
    
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"/>
    
    </android.support.design.widget.AppBarLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-02
      • 2018-06-29
      • 1970-01-01
      • 2016-04-21
      • 2019-03-25
      • 2015-12-19
      • 2021-03-24
      • 1970-01-01
      相关资源
      最近更新 更多