我正在使用AppBarLayout和CollapsingToolbarLayout与relativelayout(我的隐藏滚动内容)和工具栏包含布局(我的固定项目)。要显示一些我正在使用RecyclerView(GridLayoutManager)的项目,以及RecyclerView中显示的项目是CardView(带有线性布局)项目。
问题是当我有我的工具栏时,在RecyclerView的底部会出现空格,如果我删除工具栏的空白也会消失。问题在设备上看起来像this,看起来很正常in editor。
我尝试更改cardview和recyclerview的高度和宽度,但没有任何帮助。
我的用于cardview的xml代码,用于recyclerview中的项目:
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/white_background_rounded_corners"
android:layout_margin="5dp">
<LinearLayout
android:layout_width="156dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/white_background"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/ivCategory"
android:layout_width="156dp"
android:layout_height="100dp"
android:layout_marginTop="8dp"
android:background="@null"
android:clickable="true"
android:contentDescription="@string/category"
android:focusable="true"
android:scaleType="fitCenter"
android:src="@mipmap/android_icon" />
<TextView
android:id="@+id/tvCategoryName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="@string/text"
android:textColor="@color/mainColour"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView
这是我整个表单的xml代码(使用recyclerview的表单):
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/GrayColour"
android:orientation="vertical"
tools:context=".MainActivity">
<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"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax">
<include
android:id="@+id/Header"
layout="@layout/header_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="53dp"/>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="pin"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp">
<include
android:id="@+id/TopBar"
layout="@layout/top_navigation_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/Categories"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
tools:listitem="@layout/list_item"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toBottomOf="parent"
/>
</android.support.design.widget.CoordinatorLayout>
此处还有我的适配器,用于填充Recyclerview项目:
public class Adapter extends FirestoreAdapter<Adapter.ViewHolder> {
private static final String TAG = "Adapter";
public CategoryAdapter(Query query) {
super(query);
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new Adapter.ViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_item, parent, false));
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.bind(getSnapshot(position).toObject(Category.class));
}
public class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.ivCategory)
ImageView ivCategory;
@BindView(R.id.tvCategoryName)
TextView tvCategoryName;
public ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
public void bind(final Category category) {
StorageReference storageReference = FirebaseStorage.getInstance().getReference();
StorageReference imageRef = storageReference.child(category.getImage());
Glide.with(ivCategory)
.load(imageRef)
.into(ivCategory);
tvCategoryName.setText(category.getName());
ivCategory.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "test");
SecondActivity.start(v.getContext(), category.getName());
}
});
}
}
}
谢谢