- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试实现一个类似于 instagram 的图库模块,其中包含图像的 gridview 将独立滚动,但是如果我触摸 appbarlayout 滚动 gridview,它应该开始向上滚动。我能够通过 setnestedscrollview 实现它,但是当 appbarlayout 折叠时,它不会展开,直到我将画廊带到顶部。所以当 gridview 不在起点而是某处时,我不知道如何在触摸工具栏时展开 appbar 布局介于两者之间。这是我的 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:layout_width="match_parent"
android:id="@+id/coordinator"
android:focusableInTouchMode="false"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<GridView
android:layout_below="@+id/iv"
android:id="@+id/gridView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:columnWidth="100dp"
android:drawSelectorOnTop="true"
android:gravity="center"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:numColumns="5"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp"
android:focusable="true"
android:clickable="true"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/image"
android:src="@drawable/pup"
android:layout_width="match_parent"
android:layout_height="400dp"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:fitsSystemWindows="true"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="40dp"
app:layout_collapseMode="pin"
android:background="@android:color/transparent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
这里是我如何实现 nestedscrollview
gridView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
int y = (int)motionEvent.getRawY();
if(y<=h)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
gridView.setNestedScrollingEnabled(true);
}
else{
}
}
else
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
gridView.setNestedScrollingEnabled(false);
}
else
{
}}
return false;
}
});
最佳答案
经过大量搜索后,我开始遵循解决方案。在 xml 中, GridView 必须在 appbarlayout 之后放置在嵌套 ScrollView 中。
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true"
android:id="@+id/nsv">
<GridView
android:layout_below="@+id/iv"
android:id="@+id/gridView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:columnWidth="100dp"
android:drawSelectorOnTop="true"
android:gravity="center"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp"
android:focusable="true"
android:clickable="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.v4.widget.NestedScrollView>
和触摸网格-
int flag=1,flag2=0;
gridView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
v.getParent().requestDisallowInterceptTouchEvent(true);}
if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
int y = (int) motionEvent.getRawY();
if (flag == 1) {
if (y <= h) {
v.getParent().requestDisallowInterceptTouchEvent(false);
boolean fullyExpanded = (appBarLayout.getHeight() - appBarLayout.getBottom()) == 0;
if (fullyExpanded) {
flag2=0;
}
else
{flag2=1;
v.getParent().requestDisallowInterceptTouchEvent(true);
if(gridView.getChildAt(0).getTop()==0)
{
v.getParent().requestDisallowInterceptTouchEvent(false);
}
else
{
v.getParent().requestDisallowInterceptTouchEvent(true);}}}
else
{
v.getParent().requestDisallowInterceptTouchEvent(true);
flag2=0;}
}}
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
v.getParent().requestDisallowInterceptTouchEvent(true);
}
return false;
}});
并切换 coordinatorlayout 的触摸-
coordinatorLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
boolean fullyExpanded = (appBarLayout.getHeight() - appBarLayout.getBottom()) == 0;
if(flag2==0&&fullyExpanded)
return true;
else{
flag2=0;
return false;
}}
});
关于android - 当gridview不在顶部时如何展开appbarlayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37650920/
我目前状态的视频,以便更好地了解我的情况: video RecyclerView 上面的所有东西都在 AppbarLayout 里面 具有类似行为的 reddit 应用示例: video 目标: 1-
我正在创建一个带有 header 的 RecyclerView,当您向上滚动 RecyclerView 时 header 会折叠。我可以通过下面的布局非常接近地实现这一点,使用透明的 AppBarLa
我有一个 AppBarLayout 和 NestedScrollView。我希望 NestedScrollView 每当它向下滚动时,AppBarLayout 也应该优雅地展开,而 NestedScr
我正在尝试获取 AppBarLayout 的布局参数,但出现此错误。 java.lang.ClassCastException: android.support.design.widget.Coord
我正在为我的应用程序实现自定义 header 。在 AppBarLayout 中,我使用工具栏和我的自定义布局(名为 CustomHeader)。 我的 CustomHeader 有左下角和右下角圆角
我是编程新手,我想添加一个设置菜单按钮。 就像图片上的一样,我的应用程序没有显示三点按钮。 MainActivity.java : public class MainActivity extends
我有一个带有 fragment 的 ViewPager,其中包含一个 RecyclerView。 CollapsingTollbarLayout 位于 ViewPager 之上。一切正常,除了在 Re
我想做这个, 在 Android Studio 的预览中看起来不错,但在运行时我得到这个 正如您在屏幕开头看到的那样,颜色是白色,我想添加我自己的颜色,在本例中为绿色。 最初它使用的是 Cordina
我正在使用此布局来尝试实现可折叠的应用栏。 android:theme="@style/ThemeOverlay.AppCompat.Dark"
所以我有一个带有 AppBarLayout 和 CollapsingToolbarLayout 的 CoordinatorLayout。这是展开(左图)和折叠(右图)时的样子 我遇到的第一个问题是,当
我尽量让红色布局滚动,这样他就隐藏了,TabLayout 就留在了最上面 我需要红色布局来为我填充圆形头像的高度。我尝试将TabLayout滚动到顶部,红色布局继续滚动隐藏? 无法发送图片,请点击链接
我正在尝试从顶部为 AppBarLayout 设置动画,就像 this 中的工具栏一样视频。 这是我的布局
我需要我的 AppBarLayout 具有透明背景。 当我将 AppBarLayout 的背景更改为具有 @null 或 @android:color/transparent 时,我在工具栏的边框处看
使用 AppBarLayout 时出错,我尝试了 Clean Project 和 Rebuild Project,但它们没有用。 运行程序没有问题。这是为什么? XML 文件:
我想要实现的结果与图片上的结果几乎相同,但没有折叠并且在工具栏文本下有选项卡布局。我使用 CollapsingTollbarLayout 完成了它,但如果我不希望它折叠,我认为这不是一个好方法。我应该
我在 CoordinatorLayout 和 RecyclerView 中使用 AppBarLayout、CollapsingToolbarLayout 创建了折叠透明搜索栏。让 recyclerVi
Android Google Play 应用如何在用户点击 AppBarlayout 时动态改变颜色? 我尝试了以下方法 tabLayout.setOnTabSelectedListener(new
在页面上的任意位置下拉(过度滚动)时,我一直在努力实现 AppBarLayout 的缩放效果。 期望效果示例: https://android-arsenal.com/details/1/4443 我
当我尝试为 AppBarLayout 设置一个特定的高度值时,阴影完全消失了。 这是错误还是预期的行为? 我使用的是设计库的 26.0.0 版。 最佳答案 设置属性动画
我在 AppBarLayout 中使用了 CollapsingToolbarLayout,用户可以使用 AppBarLayout 中的 setExpanded(boolean) 方法展开或折叠它。 问
我是一名优秀的程序员,十分优秀!