【发布时间】:2020-02-08 23:53:12
【问题描述】:
我有一个显示图像、产品名称和产品图像的项目布局。我必须使用约束布局以 1:1.5 的比例显示图像。但是当我加载一个小图片时,下面的文字没有显示。
以下是我的项目 XML 代码:-
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/coordinatorLayoutCartRoot"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.jackandphantom.circularimageview.RoundedImage
android:id="@+id/imageViewSlider"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toTopOf="@id/tvTitle"
app:layout_constraintDimensionRatio="WH,1:1.4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:rounded_radius="0"
tools:src="@tools:sample/avatars" />
<TextView
android:id="@+id/tvTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="4dp"
android:text="Fitted crew neck sweater"
android:textColor="@color/colorBlack"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/imageViewSlider" />
<TextView
android:id="@+id/tvPrice"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="4dp"
android:text="$34.00"
android:textColor="@color/colorBlack"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTitle" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
- 长图输出:- https://i.imgur.com/QVnljX6.png
- 小图像输出:- https://i.imgur.com/0ZwkVwE.png
如果我用 wrap_content 替换 match_parent,应用程序会崩溃并出现以下错误:-
java.lang.IllegalStateException:页面必须填满整个 ViewPager2(使用 match_parent)
【问题讨论】:
-
如果你想改变页面高度,只需改变viewpagers的高度。
-
@Mahesh 我也有同样的问题。你找到解决办法了吗?
-
@androidStud 还没有
-
@MaheshBabariya 请参阅下面的回复。
-
是的,将其设置为 match_parent,如果您想缩小它,请尝试在视图内部或使用视图寻呼机本身进行。
标签: android android-viewpager2