【问题标题】:How to place a image using imageview below tabbed bar in android?如何在android中的标签栏下方使用imageview放置图像?
【发布时间】:2017-10-14 03:09:56
【问题描述】:

我正在使用约束布局。当我在图像视图中放置图像时,它直接垂直对齐到屏幕的中心,标签栏和图像之间有巨大的空间。我不能把它放在标签栏的正下方。图像分辨率是 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

【问题讨论】:

  • 在图像视图中添加 adjustViewBounds=true
  • 把你的完整的xml
  • 设置imageview高度wrap_content
  • 为 ImageView 赋予 android:scaleType="fitXY"
  • 为什么还要使用ConstraintLayoutRelativeLayoutLinearLayout 应该适用于此。

标签: android imageview android-constraintlayout


【解决方案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>

【讨论】:

    猜你喜欢
    • 2019-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    • 2011-03-25
    相关资源
    最近更新 更多