Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在坐标布局中放置相对坐标_Android_Android Coordinatorlayout_Android Relativelayout_Android Support Design - Fatal编程技术网

Android 如何在坐标布局中放置相对坐标

Android 如何在坐标布局中放置相对坐标,android,android-coordinatorlayout,android-relativelayout,android-support-design,Android,Android Coordinatorlayout,Android Relativelayout,Android Support Design,我正在尝试重新创建Airbnb Android应用程序中的搜索框。 因此,我将CoorinatorLayout与工具栏和回收视图一起使用 但是当我在协调器中插入除这两个东西之外的东西时,它不会显示。 这是我的密码: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.andro

我正在尝试重新创建Airbnb Android应用程序中的搜索框。 因此,我将CoorinatorLayout工具栏和回收视图一起使用

但是当我在协调器中插入除这两个东西之外的东西时,它不会显示。 这是我的密码:

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

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/red"
        app:layout_scrollFlags="scroll|enterAlways" />

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="50dp"
    android:layout_marginTop="20dp"
    android:background="@drawable/rounded_background"
    android:orientation="horizontal"
    android:padding="6dp"
    app:layout_scrollFlags="scroll|enterAlways">

    <EditText
        android:id="@+id/search"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="6"
        android:background="@null"
        android:fontFamily="sans-serif-light"
        android:hint="Unesite grad"
        android:paddingLeft="16dp"
        android:paddingStart="16dp" />

    <ImageView
        android:id="@+id/cancelSearch"
        android:layout_width="0dp"
        android:layout_height="40dp"
        android:layout_weight="1"
        android:padding="10dp"
        android:src="@drawable/ic_cancel" />
</LinearLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/appbar"
    android:background="#ffffff"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

编辑:

下面是带有RelativeLayout的代码

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

   <RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent">

       <android.support.design.widget.AppBarLayout
           android:id="@+id/appbar"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
           android:background="#00000000">

           <android.support.v7.widget.Toolbar
               android:id="@+id/toolbar"
               android:layout_width="match_parent"
               android:layout_height="?attr/actionBarSize"
               android:background="@color/red"
               app:layout_scrollFlags="scroll|enterAlways"/>
   </android.support.design.widget.AppBarLayout>

   <RelativeLayout
       android:layout_width="fill_parent"
       android:layout_height="fill_parent">
       <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginLeft="50dp"
          android:layout_marginRight="50dp"
          android:layout_marginTop="20dp"
          android:background="@drawable/rounded_background"
          android:orientation="horizontal"
          android:padding="6dp"
          app:layout_scrollFlags="scroll|enterAlways">

          <EditText
              android:id="@+id/search"
              android:layout_width="0dp"
              android:layout_height="fill_parent"
              android:layout_weight="6"
              android:background="@null"
              android:fontFamily="sans-serif-light"
              android:hint="Unesite grad"
              android:paddingLeft="16dp"
              android:paddingStart="16dp" />

          <ImageView
              android:id="@+id/cancelSearch"
              android:layout_width="0dp"
              android:layout_height="40dp"
              android:layout_weight="1"
              android:padding="10dp"
              android:src="@drawable/ic_cancel" />
      </LinearLayout>
      <android.support.v7.widget.RecyclerView
           android:id="@+id/recyclerView"
           android:layout_width="match_parent"
           android:layout_height="fill_parent"
           android:layout_below="@id/appbar"
           android:background="#ffffff"
           app:layout_behavior="@string/appbar_scrolling_view_behavior" />
   </RelativeLayout>


我试图做一些类似的事情,但在屏幕底部有一个广告横幅。我的解决方案是将
RelativeLayout
包装在
协调布局
之外,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  <android.support.design.widget.CoordinatorLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_above="@+id/ad_view">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

      <android.support.v7.widget.Toolbar
          android:id="@+id/toolbar"
          android:layout_width="match_parent"
          android:layout_height="?attr/actionBarSize"
          android:background="?attr/colorPrimary"
          app:layout_scrollFlags="scroll|enterAlways"
          app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

  <com.google.android.gms.ads.AdView
      android:id="@+id/ad_view"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_alignParentBottom="true"
      android:layout_gravity="center|bottom"
      app:adSize="SMART_BANNER"
      app:adUnitId="@string/admob_id" />

</RelativeLayout>


当在
RecyclerView
中滚动时,工具栏会正确隐藏,一切似乎都很正常。我想,如果你遵循类似的原则,你应该很乐意去做。

如果你想删除白色的状态栏,你必须删除下一行

<item name="android:statusBarColor">@android:color/transparent</item>`
@android:color/transparent`
v21/styles.xml中

例如,谢谢。


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

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/red"
            app:layout_scrollFlags="scroll|enterAlways"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/rounded_background"
            android:orientation="horizontal"
            android:padding="6dp"
            app:layout_scrollFlags="scroll|enterAlways">

            <EditText
                android:id="@+id/search"
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="6"
                android:background="@null"
                android:fontFamily="sans-serif-light"
                android:hint="Unesite grad"
                android:paddingLeft="16dp"
                android:paddingStart="16dp"/>

            <ImageView
                android:id="@+id/cancelSearch"
                android:layout_width="0dp"
                android:layout_height="40dp"
                android:layout_weight="1"
                android:padding="10dp"
                android:src="@drawable/ic_cancel" />
        </LinearLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/appbar"
        android:background="#ffffff"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>

检查这是否对您有效。

您尝试将
RelativeLayout
放入
协调布局的代码在哪里?我尝试了两种方法。首先,我将所有视图包装在CoordinatorLayout中,因此亲戚是第一个也是唯一的孩子。这导致所有元素上的滚动行为丢失。另一个在编辑中,我将RecyclerView和这个搜索框包装在相对中。@NikolaMilutinovic滚动行为将适用于所有作为
坐标布局的直接子级的子级,因此如果将布局行为设置为
RelativeLayout
,嵌套滚动将起作用。