我在ViewPager
的{{1}}内有ConstraintLayout
。如果我在dp中设置了RecycleView
具体,则两边都像这样的空白空间:
如果我将width
设置为对边的引用:
但是我希望match_constraint
可以容纳完整的RecycleView
。
但是,如果我放慢脚步,则尺寸正确,但是第一张图像不正确!)
该如何解决?
main.xml:
width
recycle.xml:
<android.support.constraint.ConstraintLayout 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:orientation="vertical"
tools:layout_editor_absoluteY="25dp">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="0dp"
android:layout_height="55dp"
app:layout_constraintBottom_toTopOf="@+id/view_pager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tabGravity="fill"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tab_layout" />
</android.support.constraint.ConstraintLayout>
ViewHolder:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_editor_absoluteY="25dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleView"
android:layout_width="0dp"
android:layout_height="430dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/cardView"
app:layout_constraintDimensionRatio=""
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="335dp"
android:layout_height="87dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.529"
app:layout_constraintStart_toStartOf="parent">
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
onCreateViewHolder:
class Holder extends RecyclerView.ViewHolder {
private ImageView imageView;
Holder(View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.imageView);
imageView.setOnClickListener((view) -> someView.onClick(
listItems.get(getAdapterPosition())));
}
void setImageView(Item item) {
ImageItem imageItem = new ImageItem(imageView);
someView.loadImage(item, imageItem, false);
Animation animation =AnimationUtils.loadAnimation(imageView.getContext(), R.anim.scale_simple);
imageView.startAnimation(animation);
}
}