假设我正在我的应用程序中制作新闻布局。第一个 ImageView 应该是主要的,这就是为什么它较大的 ImageView 和其他新闻将由较小的 ImageView 呈现。
但是当我向 firebase 添加图像和标题(主要和次要新闻)时,新闻之间会出现间距。如何消除间距?
<!-- news_item.xml -->
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="16dp">
<!-- Main News -->
<ImageView
android:id="@+id/newsImage"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/newsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="@android:color/black"
app:layout_constraintTop_toBottomOf="@+id/newsImage"
android:layout_marginTop="10dp"/>
<!-- Divider -->
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@android:color/darker_gray"
app:layout_constraintTop_toBottomOf="@id/newsTitle"/>
<!-- Secondary News -->
<ImageView
android:id="@+id/newsImageSecondary"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="18dp"
app:layout_constraintEnd_toStartOf="@+id/newsTitleSecondary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider"/>
<TextView
android:id="@+id/newsTitleSecondary"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textColor="@android:color/black"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider"/>
<View
android:id="@+id/divider2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@android:color/darker_gray"
app:layout_constraintTop_toBottomOf="@id/newsImageSecondary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- fragment_news -->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Toolbar -->
<androidx.appcompat.widget.Toolbar
android:id="@+id/transferToolbarNews"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/white"
android:elevation="4dp"
android:theme="@style/Theme.Design.Light.NoActionBar">
<TextView
android:id="@+id/toolbarTitleNews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="News"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold"/>
</androidx.appcompat.widget.Toolbar>
<!-- RecyclerView for News -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/transferToolbarNews" />
</RelativeLayout>
我尝试制作包含主要新闻和次要新闻的新闻布局。 主要新闻应位于顶部,次要新闻应位于主要新闻下方。 结果是我得到的一个低于另一个,但它们之间的间距很大。
// Change this line in the servlet
servletRequest.setAttribute("userDetails", userDetailsDTO);
// To this
servletRequest.setAttribute("loggedInUser", userDetailsDTO);