如何在android下面的标签栏下面使用imageview放置图像?

时间:2017-05-15 10:55:20

标签: android imageview android-constraintlayout

我正在使用约束布局。当我在图像视图中放置图像时,它会直接与屏幕中心对齐,标签栏和图像之间有很大的空间。我不能把它正好放在标签栏下面。图像分辨率是2048 * 1152。我打算将它用作我的应用程序的横幅。这是代码:

<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.manu.program.MainTwo">

<ImageView
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:srcCompat="@drawable/banner_image"
    />

</android.support.constraint.ConstraintLayout>

当我运行应用程序时,我得到的结果如附图need to remove the space between the image and tab bar

所示

1 个答案:

答案 0 :(得分:1)

要将图片放在标签下方,您可以使用“android:scaleType =”fitStart“。它会将您的图片放到顶部, 没有影响任何宽高比。

<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.support.v7.widget.AppCompatImageView
    android:id="@+id/section_label"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginBottom="0dp"
    android:layout_marginLeft="0dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="0dp"
    android:scaleType="fitStart"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0"
    app:srcCompat="@drawable/flower" />

</android.support.constraint.ConstraintLayout>