- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在构建一个应用程序,其中有一个显示个人资料背景图像和其他一些元素的个人资料 fragment 。就像下面的截图:
我的问题是:为什么在 AppBarLayout 的末尾有一个额外的底部填充?
这是这个 fragment 的xml布局文件(我基本上是从Cheesesquare复制过来的):
<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:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="@android:color/white"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
>
<ImageView
android:id="@+id/profile_bg"
android:layout_width="match_parent"
android:layout_height="@dimen/height_profile_background_max"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@id/avatar"
android:layout_width="@dimen/avatar_size_large"
android:layout_height="@dimen/avatar_size_large"
android:layout_marginStart="@dimen/horizontal_padding_normal"
app:civ_border_width="2dp"
app:civ_border_color="@android:color/white"
app:civ_border_overlay="false"
app:layout_constraintTop_toBottomOf="@id/profile_bg"
app:layout_constraintBottom_toBottomOf="@id/profile_bg"
app:layout_constraintStart_toStartOf="parent"
/>
<TextView
android:id="@id/user_display_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/vertical_padding_small"
android:layout_marginStart="@dimen/horizontal_padding_normal"
android:textSize="@dimen/text_size_medium"
android:textStyle="bold"
android:textColor="@color/text_color_normal"
app:layout_constraintTop_toBottomOf="@id/avatar"
app:layout_constraintStart_toStartOf="parent"
/>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/vertical_padding_small"
android:paddingBottom="@dimen/vertical_padding_normal"
android:layout_marginStart="@dimen/horizontal_padding_normal"
android:textSize="@dimen/text_size_small"
android:textColor="@color/text_color_normal"
android:maxLines="5"
app:layout_constraintTop_toBottomOf="@id/user_display_name"
app:layout_constraintStart_toStartOf="parent"
/>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/vertical_divider_height"
android:background="@color/divider_background_color"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
</android.support.constraint.ConstraintLayout>
<android.support.v7.widget.Toolbar
android:id="@id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:contentInsetStartWithNavigation="0dp"
app:layout_collapseMode="pin"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:scrollbarSize="2dp"
android:scrollbarStyle="outsideOverlay"
app:layoutManager="LinearLayoutManager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
如上所示,我没有向 AppBarLayout
添加任何填充。
我将我的布局与 Cheesesquare 进行比较,发现唯一不同的是我在 AppBarLayout 中放置了一个复杂的 ConstraintLayout
。 Cheesesquare 表现正常,因为它设置了特定值的 layout_height
:
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
当我将 AppBarLayout 的 layout_height
设置为 wrap_content
时,因为标题中的 self intro
部分可能有很多单词和它应该是 wrap_content
以确保每个句子都能显示在屏幕上。
我想知道为什么会出现这个额外的填充?仅供引用,我发现这个额外填充的高度似乎与 statusBar 的高度相同。它看起来像是与 fitsSystemWindow
属性相关的东西。如果有人能告诉我如何去除这个恼人的底部填充,那就太好了。
附言:我也为这个区域尝试了一些其他的 ViewGroup 布局,比如 LinearLayout
或 Framelayout
,它们都是一样的,所以我很确定它与 无关ConstraintLayout
我用。
最佳答案
这个问题可能是由这个 commit 引起的
我用@Bogdan Zurac 评论的方式以编程方式修复了它。
mCollapseContentLy = findViewById(R.id.ly_collapse_content);
mCollapseContentLy.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int measuredHeight = mCollapseContentLy.getMeasuredHeight();
ViewGroup.LayoutParams lp = mCollapsingToolbarLayout.getLayoutParams();
layoutParams.height = measuredHeight;
mCollapsingToolbarLayout.setLayoutParams(lp);
mCollapseContentLy.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
创建一个新类扩展 CollapsingToolbarLayout
并覆盖 onMeasure
方法
package android.support.design.widget;
import android.content.Context;
import android.util.AttributeSet;
public class GodCollapsingToolbarLayout extends CollapsingToolbarLayout {
public GodCollapsingToolbarLayout(Context context) {
this(context, null);
}
public GodCollapsingToolbarLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public GodCollapsingToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final int mode = MeasureSpec.getMode(heightMeasureSpec);
final int topInset = mLastInsets != null ? mLastInsets.getSystemWindowInsetTop() : 0;
if (mode == MeasureSpec.UNSPECIFIED && topInset > 0) {
// fix the bottom empty padding
heightMeasureSpec = MeasureSpec.makeMeasureSpec(
getMeasuredHeight() - topInset, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
关于android - 当将 fitsSystemWindows 设置为 true 时,CollapsingToolbarLayout 中的 ViewGroup 显示额外的底部填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48137666/
我有一个名为 Customview 的 viewGroup。我需要在运行时将另一个具有多个 subview 的 viewGroup 分配给 Customview。如果以上一个是可能的,我没有正确获取
我有一个包含 N 个子项的自定义 ViewGroup。现在,我创建了另一组 ViewGroup。我想将第二个 ViewGroup 添加到第一个。我怎么做?谢谢.. 最佳答案 来自代码: firstVi
我遇到了一个奇怪的问题。例如,我们有这样的布局: 我们的屏幕将变黑。如果我将 LinearLayout 替换为 FrameLayout 或 ConstraintLayout,结果相同
我希望能够以编程方式将一个 View 组添加到另一个 View 组。两者都在 xml 中定义如下,连同我的 onCreate 方法: 主.xml: secondlayout.xml:
我不确定我的问题是否可以理解。我的布局中有一个 Image 和一个 ViewGroup。 ViewGroup 与 GridView 相当,我在其中有可以拖放的项目。现在我有兴趣将我的 ViewGrou
知道为什么会出现此崩溃吗?跟踪只有 native 代码,因此很难追踪到它。当我在 Fragment 中运行动画并且当动画结束时我为 FragmentStatePagerAdapter 调用 notif
在方法内部,我调用 addView和 removeView如下: public class EnclosingClass extends FrameLayout { ... void
如何检索以“llIndex”为 id 的 linearLayout 的索引。谢谢 最佳答案 非常简单 - 在 View 的父级上调用 indexOfChild 函数:
我有子元素(不是根)RelativeLayout 的布局,然后我创建 ViewPager 并将其作为我的相对布局的子元素插入,就像 +相对布局(根) | +-- 相对布局(子) | +-- -- 浏览
我有一个布局,其根 ViewGroup 有两个 child ,其中只有一个始终可见。如果不适用,另一个 child 的可见性将在运行时设置为 View.GONE。 当两个 child 都可见时,高度设
我的 XML 布局中有以下节点: TagLayout 是一个扩展 ViewGroup 的类,基本上包含一堆带有文本的按钮(一个自定义对象,充当标签,但它既不在这里也不在那里)。 问题是当按钮太多时,
如果我尝试使用 ViewGroup,我会收到此错误 “ViewHolder cannot be resolved to a type”。没有具体的import present,如何使用? 最佳答案 也
我的自定义 ViewGroup 有问题。我连续布置了 3 个 child ,并使用 Scroller 滚动到中间的 child 。根据用户的触摸输入,我更改了应该显示的子项并请求新布局。然后我按新顺序
我正在尝试在 Android 中制作简单的翻译动画。以下不起作用: public class MyView extends ViewGroup { ... TranslateAnima
为什么 android:clipChildren="false"不工作?我想实现与 CSS overflow: visible 相同的效果,这样即使 subview 位于其父布局之外,它们也是可见的。
假设有一个包含多个子项的 ViewGroup。至于这个 ViewGroup,我想让它管理所有子项的所有 MotionEvent,这表示 VG 将 1. 能够在事件被发送到目标( child )之前拦截
我有 CustomComponent 类,它扩展了 ViewGroup。 CustomComponent源代码: public class CustomComponent extends
我的 Android 应用程序中有几个具有相同基本结构的 Activity,我正试图让我的布局变干。重复的代码如下所示。它包含一个带有页脚的可滚动区域,该页脚具有“后退”和“仪表板”链接。还有一个 F
我有一个 Android TV 布局,如下图所示。 顶部一个PagerSlidingTabStrip,从服务器拉取数据; 底部有 Fragment 的 ViewPager,每个 Fragment 都有
我正在尝试创建带有内部包含文本的指示器的 fragment slider 。 我在网上找到了一些包含图像 slider 的教程,并将其编辑为文本 slider ,但我收到了此错误消息: android
我是一名优秀的程序员,十分优秀!