我的项目在ViewPager中包含一个activity_main.xml布局和3个片段xml布局。 片段2和3(" help_us"和#34;会话")包含RecyclerView。 Frgemnent 2包含带有EditText的线性布局。
我只想在滚动Recyclerviews时隐藏AppBar!
我遵循了本教程 https://mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling%28part3%29/ 没有结果。
所以我有两个问题: 1-他妈的我错过了什么? (我想哭) 2-当我在Fragment 2的EditText中输入一些文本时......猜猜是什么? Appbar崩溃了!永远不会回来......这显然不是一种理想的行为......
好的,我是一个肮脏的菜鸟。但有谁看到我怎么能解决这些问题?
以下是我的布局
activity_main.xml中
<?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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_black_matxxxhdpi"
android:fitsSystemWindows="true"
app:statusBarBackground="@android:color/transparent"
tools:context="com.example.philipp.us.MainActivity">
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="550dp"
android:background="@drawable/background_black_logo_white_mediumxxxhdpi"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="@android:color/transparent"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginLeft="45dp"
android:layout_marginRight="20dp"
android:background="@android:color/transparent"
android:elevation="4dp"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.AppBarOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/submit_question"
android:layout_width="76dp"
android:layout_height="76dp"
android:layout_gravity="top|center_horizontal"
android:layout_marginEnd="10dp"
android:background="@android:color/transparent"
android:clickable="true"
android:onClick="onSubmitQuestion"
app:backgroundTint="@android:color/transparent"
app:fabSize="normal"
app:layout_anchor="@+id/container"
app:layout_anchorGravity="bottom|right|center"
app:srcCompat="@drawable/_btn_askus_normalxxxhdpi"
app:useCompatPadding="true" />
</android.support.design.widget.CoordinatorLayout>`
片段2.xml
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:background="@android:color/transparent"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:weightSum="100"
tools:context="com.example.philipp.us.HelpUsFragment">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/white_transparent">
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="7"
android:background="@android:color/transparent"
android:paddingStart="8dp"
android:weightSum="100">
<ImageButton
android:id="@+id/btn_localisation"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginEnd="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_weight="10"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:cropToPadding="false"
android:onClick="onUpdateFilterLocation"
android:scaleType="centerCrop"
android:tint="@color/white_transparent"
app:srcCompat="@drawable/custom_button_localisation_filter"
tools:ignore="ContentDescription,NestedWeights" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_weight="20"
android:background="@android:color/transparent"
android:orientation="vertical"
android:weightSum="100">
<EditText
android:id="@+id/lbl_filter_city"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:background="@android:color/transparent"
android:ellipsize="end"
android:gravity="center"
android:hint="@string/hint_city_search"
android:inputType="text|textCapWords|textAutoCorrect"
android:lines="1"
android:maxLines="1"
android:minLines="1"
android:scrollHorizontally="true"
android:selectAllOnFocus="true"
android:textAlignment="center"
android:textColor="@color/white"
android:textColorHint="@color/white_transparent"
android:textColorLink="@color/colorHintText"
android:textSize="12sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:background="@android:color/transparent"
android:elevation="0dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="100"
tools:targetApi="lollipop">
<EditText
android:id="@+id/lbl_filter_value_radius"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="50"
android:background="@android:color/transparent"
android:hint="@string/hint_radius_filter_novalue"
android:inputType="number"
android:lines="1"
android:maxEms="3"
android:maxLength="3"
android:maxLines="1"
android:minLines="1"
android:scrollHorizontally="true"
android:selectAllOnFocus="true"
android:textAlignment="viewEnd"
android:textColor="@color/white"
android:textSize="12sp" />
<TextView
android:id="@+id/lbl_unit_distance"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="3dp"
android:layout_marginStart="3dp"
android:layout_weight="50"
android:background="@android:color/transparent"
android:text="@string/unit_distance"
android:textAlignment="textStart"
android:textColor="@color/white_transparent"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/black"
android:orientation="horizontal"
android:visibility="gone">
</LinearLayout>
<EditText
android:id="@+id/lbl_filter_keyword"
style="@style/EditTextTheme"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="5dp"
android:layout_weight="60"
android:backgroundTint="@color/white_transparent"
android:clipToPadding="true"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜßäöüŒÀÂÇÈÉÊËÎÏÔÛÜœàâçèéêëîïôùûüáíóúñÑ-"
android:gravity="center_vertical"
android:hint="@string/hint_search_filter"
android:imeOptions="actionSearch"
android:inputType="textCapWords|textAutoCorrect"
android:maxLines="1"
android:minLines="1"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:selectAllOnFocus="true"
android:textColor="@color/white"
android:textColorHint="@color/white_transparent"
android:textSize="18sp" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/black"
android:orientation="horizontal"
android:visibility="gone">
</LinearLayout>
<ImageButton
android:id="@+id/btn_filter_search"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_gravity="center"
android:layout_margin="5dp"
android:layout_weight="10"
android:background="@android:color/transparent"
android:onClick="onFilterQuestions"
android:scaleType="centerInside"
android:tint="@color/white_transparent"
app:srcCompat="@drawable/custom_button_search"
tools:ignore="ContentDescription" />
</LinearLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefresh"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="93">
<android.support.v7.widget.RecyclerView
android:id="@+id/question_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:fadingEdgeLength="10dp"
android:isScrollContainer="false"
android:requiresFadingEdge="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
片段3.xml
<LinearLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@android:color/transparent"
android:orientation="vertical"
android:weightSum="100"
tools:context=".ConversationFragment">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/white_transparent">
</FrameLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/conv_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:fadingEdgeLength="10dp"
android:paddingTop="10dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
非常感谢
答案 0 :(得分:0)
我解决了我的问题。 后人: 在我的activity_main.xml中,Viewpager布局有一个固定值:android:layout_height =“550dp”。 因此,使用android:layout_height =“match_parent”问题就解决了。
现在,整个activity_main布局略微超过手机边框。
如果有人看到发生的事情,我会很感激解决方案。