gpt4 book ai didi

android - 带有 RecyclerView 的 LinearLayout 在 CardView 外滚动时隐藏 ImageView

转载 作者:行者123 更新时间:2023-11-29 18:52:57 26 4
gpt4 key购买 nike

我正在尝试在 cardview 中使用 recyclerview 进行 Activity 。在 cardview 上方有一个图像,当我滚动 recyclerview 但不使浅蓝色框消失时,我希望它消失。我怎样才能做到这一点?我尝试使用 NestedScrollView 但没有结果

Actual layout

这是我的布局代码

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionName="itemMainTransition"
tools:context=".activity.WeatherActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
android:id="@+id/meteoTrentinoBanner"
android:background="#42a4ce"
android:src="@drawable/logo_meteotn"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:orientation="horizontal"
android:background="@drawable/weather_border">

<ImageView
android:id="@+id/backDay"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_back"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewMinTemp"
android:layout_width="40dp"
android:layout_height="match_parent"
android:textAlignment="center"
android:gravity="center_vertical|center_horizontal"
android:textSize="19sp"
android:textStyle="bold"
android:textColor="#0000FF"/>
<TextView
android:id="@+id/textViewDay"
android:text="@string/oggi"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:textAlignment="center"
android:textSize="25sp"
android:textStyle="bold"
tools:ignore="NestedWeights" />
<TextView
android:id="@+id/textViewMaxTemp"
android:layout_width="40dp"
android:layout_height="match_parent"
android:textAlignment="center"
android:gravity="center_vertical|center_horizontal"
android:textSize="19sp"
android:textStyle="bold"
android:textColor="#FF0000"/>
</LinearLayout>

<ImageView
android:id="@+id/forwardDay"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_forward"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:orientation="horizontal"
android:background="@drawable/weather_border">
<ImageView
android:id="@+id/meteoInfo"
android:layout_width="40dp"
android:layout_height="match_parent"
android:src="@drawable/ic_info"/>

<TextView
android:id="@+id/textViewWeather"
android:textSize="23sp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewMeteo"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LeaveActivity">

<ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/colorPrimary" />

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">


<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

<ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:contentDescription="@string/app_name"
android:src="@mipmap/ic_launcher"
app:layout_collapseMode="parallax" />
</android.support.design.widget.CollapsingToolbarLayout>

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


<LinearLayout
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">


<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardElevation="5dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/resView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</android.support.v4.widget.NestedScrollView>


</android.support.v7.widget.CardView>
</LinearLayout>

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

关于android - 带有 RecyclerView 的 LinearLayout 在 CardView 外滚动时隐藏 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50526047/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com