2017-04-19 204 views
1

在预棒棒糖设备上,工具栏消失了,但如果将ScrollBar可见性设置为gone,则会出现工具栏。它在运行棒棒糖或更高版本的设备上工作正常。ScrollView使工具栏在Pre-Lollipop设备上消失

这里是预期的观点:

enter image description here

这里是我的布局:

<?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:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:background="@android:color/transparent" 
     android:elevation="0.5dp"> 

     <TextView 
      android:id="@+id/toolbarText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="About Desh Travel" 
      android:textColor="#ffffff" 
      android:textSize="20sp" 
      android:visibility="invisible" /> 
    </android.support.v7.widget.Toolbar> 

    <ScrollView 
     android:id="@+id/busInformationActivityScrollView" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#FFFFFF" 
      android:paddingBottom="20dp"> 


      <!-- Image for the bus cover--> 

      <ImageView 
       android:id="@+id/busCover" 
       android:layout_width="match_parent" 
       android:layout_height="198dp" 
       android:contentDescription="Cover for the Bus" 
       android:scaleType="fitXY" /> 

      <!-- Layout for the Bus name and the rating--> 

      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignBottom="@+id/busCover" 
       android:background="#28000000" 
       android:padding="7dp"> 

       <TextView 
        android:id="@+id/busName" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="12dp" 
        android:layout_marginStart="12dp" 
        android:text="Desh Travels" 
        android:textColor="#FFF" 
        android:textSize="20sp" /> 

       <com.iarcuschin.simpleratingbar.SimpleRatingBar 
        android:id="@+id/ratingBar" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="end|center_vertical" 
        android:layout_marginEnd="12dp" 
        android:layout_marginRight="12dp" 
        android:visibility="gone" 
        app:srb_borderColor="#f1bc0e" 
        app:srb_fillColor="#e5e917" 
        app:srb_numberOfStars="5" 
        app:srb_rating="3" 
        app:srb_starBackgroundColor="#f7f9d8" 
        app:srb_starBorderWidth="0.5" 
        app:srb_starSize="15dp" 
        app:srb_starsSeparation="2dp" 
        app:srb_stepSize="1" /> 

      </FrameLayout> 

      <!-- Description of the bus--> 

      <TextView 
       android:id="@+id/busDescription" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/busCover" 
       android:layout_marginTop="2dp" 
       android:gravity="start" 
       android:padding="20dp" 
       android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus non turpis quam. Sed at sagittis felis. Maecenas blandit vestibulum lorem, quis efficitur diam tempus in." 
       android:textColor="#3E3E3E" 
       android:textSize="12.5sp" /> 

      <!--Separator--> 

      <View 
       android:id="@+id/viewSeparator" 
       android:layout_width="match_parent" 
       android:layout_height="0.5dp" 
       android:layout_below="@+id/busDescription" 
       android:layout_marginLeft="55dp" 
       android:layout_marginRight="55dp" 
       android:layout_marginTop="5dp" /> 

      <!-- Info of the bus--> 

      <!-- 1st Para--> 
      <TextView 
       android:id="@+id/launchedTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_below="@+id/viewSeparator" 
       android:layout_marginLeft="20dp" 
       android:layout_marginStart="20dp" 
       android:text="Launched" 
       android:textColor="#01AA4F" 
       android:textSize="13.5sp" /> 

      <TextView 
       android:id="@+id/totalBusTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/viewSeparator" 
       android:layout_centerHorizontal="true" 
       android:layout_marginLeft="90dp" 
       android:layout_marginStart="90dp" 
       android:text="Total Bus" 
       android:textColor="#01AA4F" 
       android:textSize="13.5sp" /> 

      <TextView 
       android:id="@+id/acBusTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 
       android:layout_below="@+id/viewSeparator" 
       android:layout_marginEnd="20dp" 
       android:layout_marginRight="20dp" 
       android:text="AC Bus" 
       android:textColor="#01AA4F" 
       android:textSize="13.5sp" /> 

      <!--1st Info Para--> 

      <TextView 
       android:id="@+id/launched" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/launchedTitle" 
       android:layout_alignStart="@id/launchedTitle" 
       android:layout_alignTop="@id/launchedTitle" 
       android:layout_marginTop="15dp" 
       android:text="2009" 
       android:textColor="#000000" 
       android:textSize="12.5sp" /> 

      <TextView 
       android:id="@+id/totalBus" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/totalBusTitle" 
       android:layout_alignStart="@id/totalBusTitle" 
       android:layout_alignTop="@id/totalBusTitle" 
       android:layout_marginTop="15dp" 
       android:text="50" 
       android:textColor="#000000" 
       android:textSize="12.5sp" /> 

      <TextView 
       android:id="@+id/acBus" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/acBusTitle" 
       android:layout_alignStart="@id/acBusTitle" 
       android:layout_alignTop="@id/acBusTitle" 
       android:layout_marginTop="15dp" 
       android:text="24" 
       android:textColor="#000000" 
       android:textSize="12.5sp" /> 

      <!-- 2nd Para--> 

      <TextView 
       android:id="@+id/nonACBusTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/launched" 
       android:layout_alignStart="@id/launched" 
       android:layout_alignTop="@id/launched" 
       android:layout_marginTop="25dp" 
       android:text="Non AC Bus" 
       android:textColor="#01AA4F" 
       android:textSize="13.5sp" /> 

      <TextView 
       android:id="@+id/busRatingTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/totalBus" 
       android:layout_alignStart="@id/totalBus" 
       android:layout_alignTop="@id/totalBus" 
       android:layout_marginTop="25dp" 
       android:text="Rating" 
       android:textColor="#01AA4F" 
       android:textSize="13.5sp" /> 

      <TextView 
       android:id="@+id/eTicketTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/acBus" 
       android:layout_alignStart="@id/acBus" 
       android:layout_alignTop="@id/acBus" 
       android:layout_marginTop="25dp" 
       android:text="eTicket" 
       android:textColor="#01AA4F" 
       android:textSize="13.5sp" /> 

      <!-- 2nd Info Para--> 

      <TextView 
       android:id="@+id/nonACBus" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/nonACBusTitle" 
       android:layout_alignStart="@id/nonACBusTitle" 
       android:layout_alignTop="@id/nonACBusTitle" 
       android:layout_marginTop="15dp" 
       android:text="26" 
       android:textColor="#000000" 
       android:textSize="12.5sp" /> 

      <TextView 
       android:id="@+id/busRating" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/busRatingTitle" 
       android:layout_alignStart="@id/busRatingTitle" 
       android:layout_alignTop="@id/busRatingTitle" 
       android:layout_marginTop="15dp" 
       android:text="Rate" 
       android:textColor="#000000" 
       android:textSize="12.5sp" /> 

      <TextView 
       android:id="@+id/eTicket" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/eTicketTitle" 
       android:layout_alignStart="@id/eTicketTitle" 
       android:layout_alignTop="@id/eTicketTitle" 
       android:layout_marginTop="15dp" 
       android:text="Yes" 
       android:textColor="#000000" 
       android:textSize="12.5sp" /> 

      <!-- Counter List Button--> 

      <Button 
       android:id="@+id/counterListButton" 
       style="?android:attr/borderlessButtonStyle" 
       android:layout_width="match_parent" 
       android:layout_height="32dp" 
       android:layout_below="@id/busRating" 
       android:layout_centerHorizontal="true" 
       android:layout_marginLeft="45dp" 
       android:layout_marginRight="45dp" 
       android:layout_marginTop="35dp" 
       android:background="#00D463" 
       android:paddingLeft="22dp" 
       android:paddingRight="22dp" 
       android:text="Counter List" 
       android:textAllCaps="false" 
       android:textColor="#FFF" 
       android:textSize="15sp" /> 


      <ImageView 
       android:id="@+id/firstImage" 
       android:layout_width="100dp" 
       android:layout_height="80dp" 
       android:layout_below="@+id/counterListButton" 
       android:layout_marginRight="18dp" 
       android:layout_marginTop="20dp" 
       android:layout_toLeftOf="@+id/secondImage" 
       android:scaleType="centerCrop" 
       android:src="@drawable/placeholder" /> 

      <ImageView 
       android:id="@+id/secondImage" 
       android:layout_width="100dp" 
       android:layout_height="80dp" 
       android:layout_below="@+id/counterListButton" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="20dp" 
       android:scaleType="centerCrop" 
       android:src="@drawable/placeholder" /> 

      <ImageView 
       android:id="@+id/thirdImage" 
       android:layout_width="100dp" 
       android:layout_height="80dp" 
       android:layout_below="@+id/counterListButton" 
       android:layout_marginLeft="18dp" 
       android:layout_marginTop="20dp" 
       android:layout_toRightOf="@+id/secondImage" 
       android:scaleType="centerCrop" 
       android:src="@drawable/placeholder" /> 


      <ImageView 
       android:id="@+id/fourthImage" 
       android:layout_width="100dp" 
       android:layout_height="80dp" 
       android:layout_below="@+id/firstImage" 
       android:layout_marginRight="18dp" 
       android:layout_marginTop="18dp" 
       android:layout_toLeftOf="@+id/fifthImage" 
       android:scaleType="centerCrop" 
       android:src="@drawable/placeholder" /> 

      <ImageView 
       android:id="@+id/fifthImage" 
       android:layout_width="100dp" 
       android:layout_height="80dp" 
       android:layout_below="@+id/firstImage" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="18dp" 
       android:scaleType="centerCrop" 
       android:src="@drawable/placeholder" /> 

      <ImageView 
       android:id="@+id/sixthImage" 
       android:layout_width="100dp" 
       android:layout_height="80dp" 
       android:layout_below="@+id/firstImage" 
       android:layout_marginLeft="18dp" 
       android:layout_marginTop="18dp" 
       android:layout_toRightOf="@+id/fifthImage" 
       android:scaleType="centerCrop" 
       android:src="@drawable/placeholder" /> 

     </RelativeLayout> 
    </ScrollView> 
</RelativeLayout> 
+0

我会建议,使用线性布局为主要布局,其中方向=垂直将解决你的问题。 –

+0

尝试添加'fillviewport =“true”'为滚动视图...在布局xml – rafsanahmad007

+0

@ Er.TysonSubba,我不想使用线性布局,因为这将使工具栏下方的ScrollView,但我想工具栏在顶部和它后面的滚动视图 –

回答

2

更新:

把你Toolbar布局下面ScrollView

试试这个:

<?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:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <ScrollView 
     android:id="@+id/busInformationActivityScrollView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#FFFFFF" 
      android:paddingBottom="20dp"> 

      <!-- Image for the bus cover--> 
      <ImageView 
       android:id="@+id/busCover" 
       android:layout_width="match_parent" 
       android:layout_height="198dp" 
       android:contentDescription="Cover for the Bus" 
       android:scaleType="fitXY" /> 

      <!-- Layout for the Bus name and the rating--> 

      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignBottom="@+id/busCover" 
       android:background="#28000000" 
       android:padding="7dp"> 

       <TextView 
        android:id="@+id/busName" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="12dp" 
        android:layout_marginStart="12dp" 
        android:text="Desh Travels" 
        android:textColor="#FFF" 
        android:textSize="20sp" /> 

       <com.iarcuschin.simpleratingbar.SimpleRatingBar 
        android:id="@+id/ratingBar" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="end|center_vertical" 
        android:layout_marginEnd="12dp" 
        android:layout_marginRight="12dp" 
        android:visibility="gone" 
        app:srb_borderColor="#f1bc0e" 
        app:srb_fillColor="#e5e917" 
        app:srb_numberOfStars="5" 
        app:srb_rating="3" 
        app:srb_starBackgroundColor="#f7f9d8" 
        app:srb_starBorderWidth="0.5" 
        app:srb_starSize="15dp" 
        app:srb_starsSeparation="2dp" 
        app:srb_stepSize="1" /> 

      </FrameLayout> 

      <!-- Description of the bus--> 

      <TextView 
       android:id="@+id/busDescription" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/busCover" 
       android:layout_marginTop="2dp" 
       android:gravity="start" 
       android:padding="20dp" 
       android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus non turpis quam. Sed at sagittis felis. Maecenas blandit vestibulum lorem, quis efficitur diam tempus in." 
       android:textColor="#3E3E3E" 
       android:textSize="12.5sp" /> 

      <!--Separator--> 

      <View 
       android:id="@+id/viewSeparator" 
       android:layout_width="match_parent" 
       android:layout_height="0.5dp" 
       android:layout_below="@+id/busDescription" 
       android:layout_marginLeft="55dp" 
       android:layout_marginRight="55dp" 
       android:layout_marginTop="5dp" /> 

      <!-- Info of the bus--> 

      <!-- 1st Para--> 
      <TextView 
       android:id="@+id/launchedTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_below="@+id/viewSeparator" 
       android:layout_marginLeft="20dp" 
       android:layout_marginStart="20dp" 
       android:text="Launched" 
       android:textColor="#01AA4F" 
       android:textSize="13.5sp" /> 

      <TextView 
       android:id="@+id/totalBusTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/viewSeparator" 
       android:layout_centerHorizontal="true" 
       android:layout_marginLeft="90dp" 
       android:layout_marginStart="90dp" 
       android:text="Total Bus" 
       android:textColor="#01AA4F" 
       android:textSize="13.5sp" /> 

      <TextView 
       android:id="@+id/acBusTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 
       android:layout_below="@+id/viewSeparator" 
       android:layout_marginEnd="20dp" 
       android:layout_marginRight="20dp" 
       android:text="AC Bus" 
       android:textColor="#01AA4F" 
       android:textSize="13.5sp" /> 

      <!--1st Info Para--> 

      <TextView 
       android:id="@+id/launched" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/launchedTitle" 
       android:layout_alignStart="@id/launchedTitle" 
       android:layout_alignTop="@id/launchedTitle" 
       android:layout_marginTop="15dp" 
       android:text="2009" 
       android:textColor="#000000" 
       android:textSize="12.5sp" /> 

      <TextView 
       android:id="@+id/totalBus" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/totalBusTitle" 
       android:layout_alignStart="@id/totalBusTitle" 
       android:layout_alignTop="@id/totalBusTitle" 
       android:layout_marginTop="15dp" 
       android:text="50" 
       android:textColor="#000000" 
       android:textSize="12.5sp" /> 

      <TextView 
       android:id="@+id/acBus" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/acBusTitle" 
       android:layout_alignStart="@id/acBusTitle" 
       android:layout_alignTop="@id/acBusTitle" 
       android:layout_marginTop="15dp" 
       android:text="24" 
       android:textColor="#000000" 
       android:textSize="12.5sp" /> 

      <!-- 2nd Para--> 

      <TextView 
       android:id="@+id/nonACBusTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/launched" 
       android:layout_alignStart="@id/launched" 
       android:layout_alignTop="@id/launched" 
       android:layout_marginTop="25dp" 
       android:text="Non AC Bus" 
       android:textColor="#01AA4F" 
       android:textSize="13.5sp" /> 

      <TextView 
       android:id="@+id/busRatingTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/totalBus" 
       android:layout_alignStart="@id/totalBus" 
       android:layout_alignTop="@id/totalBus" 
       android:layout_marginTop="25dp" 
       android:text="Rating" 
       android:textColor="#01AA4F" 
       android:textSize="13.5sp" /> 

      <TextView 
       android:id="@+id/eTicketTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/acBus" 
       android:layout_alignStart="@id/acBus" 
       android:layout_alignTop="@id/acBus" 
       android:layout_marginTop="25dp" 
       android:text="eTicket" 
       android:textColor="#01AA4F" 
       android:textSize="13.5sp" /> 

      <!-- 2nd Info Para--> 

      <TextView 
       android:id="@+id/nonACBus" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/nonACBusTitle" 
       android:layout_alignStart="@id/nonACBusTitle" 
       android:layout_alignTop="@id/nonACBusTitle" 
       android:layout_marginTop="15dp" 
       android:text="26" 
       android:textColor="#000000" 
       android:textSize="12.5sp" /> 

      <TextView 
       android:id="@+id/busRating" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/busRatingTitle" 
       android:layout_alignStart="@id/busRatingTitle" 
       android:layout_alignTop="@id/busRatingTitle" 
       android:layout_marginTop="15dp" 
       android:text="Rate" 
       android:textColor="#000000" 
       android:textSize="12.5sp" /> 

      <TextView 
       android:id="@+id/eTicket" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@id/eTicketTitle" 
       android:layout_alignStart="@id/eTicketTitle" 
       android:layout_alignTop="@id/eTicketTitle" 
       android:layout_marginTop="15dp" 
       android:text="Yes" 
       android:textColor="#000000" 
       android:textSize="12.5sp" /> 

      <!-- Counter List Button--> 

      <Button 
       android:id="@+id/counterListButton" 
       style="?android:attr/borderlessButtonStyle" 
       android:layout_width="match_parent" 
       android:layout_height="32dp" 
       android:layout_below="@id/busRating" 
       android:layout_centerHorizontal="true" 
       android:layout_marginLeft="45dp" 
       android:layout_marginRight="45dp" 
       android:layout_marginTop="35dp" 
       android:background="#00D463" 
       android:paddingLeft="22dp" 
       android:paddingRight="22dp" 
       android:text="Counter List" 
       android:textAllCaps="false" 
       android:textColor="#FFF" 
       android:textSize="15sp" /> 


      <ImageView 
       android:id="@+id/firstImage" 
       android:layout_width="100dp" 
       android:layout_height="80dp" 
       android:layout_below="@+id/counterListButton" 
       android:layout_marginRight="18dp" 
       android:layout_marginTop="20dp" 
       android:layout_toLeftOf="@+id/secondImage" 
       android:scaleType="centerCrop" 
       android:src="@drawable/placeholder" /> 

      <ImageView 
       android:id="@+id/secondImage" 
       android:layout_width="100dp" 
       android:layout_height="80dp" 
       android:layout_below="@+id/counterListButton" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="20dp" 
       android:scaleType="centerCrop" 
       android:src="@drawable/placeholder" /> 

      <ImageView 
       android:id="@+id/thirdImage" 
       android:layout_width="100dp" 
       android:layout_height="80dp" 
       android:layout_below="@+id/counterListButton" 
       android:layout_marginLeft="18dp" 
       android:layout_marginTop="20dp" 
       android:layout_toRightOf="@+id/secondImage" 
       android:scaleType="centerCrop" 
       android:src="@drawable/placeholder" /> 


      <ImageView 
       android:id="@+id/fourthImage" 
       android:layout_width="100dp" 
       android:layout_height="80dp" 
       android:layout_below="@+id/firstImage" 
       android:layout_marginRight="18dp" 
       android:layout_marginTop="18dp" 
       android:layout_toLeftOf="@+id/fifthImage" 
       android:scaleType="centerCrop" 
       android:src="@drawable/placeholder" /> 

      <ImageView 
       android:id="@+id/fifthImage" 
       android:layout_width="100dp" 
       android:layout_height="80dp" 
       android:layout_below="@+id/firstImage" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="18dp" 
       android:scaleType="centerCrop" 
       android:src="@drawable/placeholder" /> 

      <ImageView 
       android:id="@+id/sixthImage" 
       android:layout_width="100dp" 
       android:layout_height="80dp" 
       android:layout_below="@+id/firstImage" 
       android:layout_marginLeft="18dp" 
       android:layout_marginTop="18dp" 
       android:layout_toRightOf="@+id/fifthImage" 
       android:scaleType="centerCrop" 
       android:src="@drawable/placeholder" /> 

     </RelativeLayout> 
    </ScrollView> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:background="@android:color/transparent" 
     android:elevation="0.5dp"> 

     <TextView 
      android:id="@+id/toolbarText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="About Desh Travel" 
      android:textColor="#ffffff" 
      android:textSize="20sp" 
      android:visibility="invisible" /> 
    </android.support.v7.widget.Toolbar> 

</RelativeLayout> 

仅供参考,您还可以通过使用CollapsingToolbarLayoutNestedScrollViewCoordinatorLayout实现这种行为。

这里有一些很好的教程:

https://antonioleiva.com/collapsing-toolbar-layout/ http://guides.codepath.com/android/handling-scrolls-with-coordinatorlayout

希望这将有助于〜

+0

这将使ScrollView在我不想要的工具栏下面,这是我想要的,https://imghost.io/images/2017/04/19/Screenshot_1492593085.md.png这是当设置layout_below https:// imghost时我得到了什么。io/images/2017/04/19/Screenshot_1492593062.md.png –

+0

现在正在工作! :)感谢:D –

+0

如果我的答案似乎有用,不要忘记给一个投票。阅读http://stackoverflow.com/help/someone-answers – FAT

1

加入滚动型

android:layout_below="@+id/toolbar" 

编辑

您可以使用AppBarLayoutCoordinatorLayout不同的滚动行为看sample

+1

这将使ScrollView在我不想要的工具栏下,这是我想要的, https://imghost.io/images/ 2017/04/19/Screenshot_1492593085.md.png 这就是我设置layout_below时得到的 htt ps://imghost.io/images/2017/04/19/Screenshot_1492593062.md.png –

+0

那你想要什么?你没有澄清问题 –

+0

其实不,我只是想让工具栏停留在顶部,我使用onScrollListener来改变工具栏的颜色。 Ferdous Ahamed的答案解决了这个问题 –