【问题标题】:Scrollview on Relative layout overlapping on toolbar相对布局中的滚动视图在工具栏上重叠
【发布时间】:2016-08-17 12:12:48
【问题描述】:

我的 .xml 上的滚动视图正在工作,但它在工具栏上重叠我无法再按层次结构,如果这是问题,我刚刚将我的 android studio 更新到 2.2 Beta idk。

在这里。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout 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:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.kun.carkila.DetailActivity"
tools:showIn="@layout/activity_detail">


<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/etResDate"
    android:editable="false"
    android:hint="Reservation Date"
    android:layout_below="@+id/etPickup"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/etResTime"
    android:editable="false"
    android:hint="Reservation Time"
    android:layout_below="@+id/etResDate"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:id="@+id/etPickup"
    android:hint="Pickup Location"
    android:layout_below="@+id/tvPoster"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="22dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/etReturnTime"
    android:editable="false"
    android:hint="Return Time"
    android:layout_below="@+id/etReturnDate"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Rent"
    android:id="@+id/btnRent"
    android:layout_below="@+id/etReturnTime"
    android:layout_centerHorizontal="true" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/ivImage"
    android:src="@android:drawable/star_big_on"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Large Text"
    android:id="@+id/tvCarModel"
    android:layout_below="@+id/ivImage"
    android:layout_centerHorizontal="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Large Text"
    android:id="@+id/tvCarType"
    android:layout_below="@+id/tvCarModel"
    android:layout_alignLeft="@+id/tvCarModel"
    android:layout_alignStart="@+id/tvCarModel" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Large Text"
    android:id="@+id/tvCapacity"
    android:layout_below="@+id/tvCarType"
    android:layout_alignLeft="@+id/tvCarType"
    android:layout_alignStart="@+id/tvCarType" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Large Text"
    android:id="@+id/tvFuelType"
    android:layout_below="@+id/tvCapacity"
    android:layout_centerHorizontal="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Large Text"
    android:id="@+id/tvPoster"
    android:layout_below="@+id/tvPlateNumber"
    android:layout_alignLeft="@+id/tvPlateNumber"
    android:layout_alignStart="@+id/tvPlateNumber" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Large Text"
    android:id="@+id/tvPlateNumber"
    android:layout_below="@+id/tvFuelType"
    android:layout_alignLeft="@+id/tvFuelType"
    android:layout_alignStart="@+id/tvFuelType" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/etReturnDate"
    android:editable="false"
    android:hint="Return Date"
    android:layout_below="@+id/etResTime"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

</RelativeLayout>

【问题讨论】:

  • 请提供屏幕截图。
  • @AmitVaghela - 我更新了忘记添加滚动视图的代码。对不起。
  • @jaydroider - 先生,我已经更新了屏幕截图。 :)
  • @J.Shmoe 为什么你拿了这个app:layout_behavior="@string/appbar_scrolling_view_behavior" 删除它并检查。
  • @jaydroider - 现在好了,先生。我只是将app:layout_behavior‌​="@string/appbar_scro‌​lling_view_behavior" 放在滚动视图上而不是相对布局上。谢谢你,先生!请将评论转换为答案。 :)

标签: android scrollview android-relativelayout


【解决方案1】:

Relative Layout 中删除此app:layout_behavior‌​="@string/appbar_scro‌​lling_view_behavior"

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

  <RelativeLayout 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:orientation="vertical"
    tools:context="com.example.kun.carkila.DetailActivity"
    tools:showIn="@layout/activity_detail">

【讨论】:

    【解决方案2】:
    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <RelativeLayout 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:orientation="vertical"
            tools:context="com.example.kun.carkila.DetailActivity">
    
    
            <EditText
                android:id="@+id/etResDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/etPickup"
                android:editable="false"
                android:hint="Reservation Date" />
    
            <EditText
                android:id="@+id/etResTime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/etResDate"
                android:editable="false"
                android:hint="Reservation Time" />
    
            <EditText
                android:id="@+id/etPickup"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/tvPoster"
                android:layout_marginTop="22dp"
                android:ems="10"
                android:hint="Pickup Location"
                android:inputType="textPersonName" />
    
            <EditText
                android:id="@+id/etReturnTime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/etReturnDate"
                android:editable="false"
                android:hint="Return Time" />
    
            <Button
                android:id="@+id/btnRent"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/etReturnTime"
                android:layout_centerHorizontal="true"
                android:text="Rent" />
    
            <ImageView
                android:id="@+id/ivImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:src="@android:drawable/star_big_on" />
    
            <TextView
                android:id="@+id/tvCarModel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/ivImage"
                android:layout_centerHorizontal="true"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
    
            <TextView
                android:id="@+id/tvCarType"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/tvCarModel"
                android:layout_alignStart="@+id/tvCarModel"
                android:layout_below="@+id/tvCarModel"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
    
            <TextView
                android:id="@+id/tvCapacity"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/tvCarType"
                android:layout_alignStart="@+id/tvCarType"
                android:layout_below="@+id/tvCarType"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
    
            <TextView
                android:id="@+id/tvFuelType"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/tvCapacity"
                android:layout_centerHorizontal="true"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
    
            <TextView
                android:id="@+id/tvPoster"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/tvPlateNumber"
                android:layout_alignStart="@+id/tvPlateNumber"
                android:layout_below="@+id/tvPlateNumber"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
    
            <TextView
                android:id="@+id/tvPlateNumber"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/tvFuelType"
                android:layout_alignStart="@+id/tvFuelType"
                android:layout_below="@+id/tvFuelType"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
    
            <EditText
                android:id="@+id/etReturnDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/etResTime"
                android:editable="false"
                android:hint="Return Date" />
    
        </RelativeLayout>
    </ScrollView>
    

    检查是否有帮助

    【讨论】:

      【解决方案3】:

      请执行以下 XML 代码之类的操作,或者只是在 NestedScrollView 之间添加您的 EditText/TextView 组件。

      <?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"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/addtimesheetlayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.example.kun.carkila.DetailActivity"
      android:orientation="vertical">
      
      <android.support.v4.widget.NestedScrollView
      android:id="@+id/scrollableview"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scrollbars="vertical"
      app:layout_behavior="@string/appbar_scrolling_view_behavior">
      
      <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical">
      <!--Add your EditText here-->
      
      
      </LinearLayout><!--Main layout ends-->
      
      </android.support.v4.widget.NestedScrollView>
      
      </LinearLayout>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-03
        • 1970-01-01
        • 2015-10-10
        相关资源
        最近更新 更多