【问题标题】:Image Height Exceeding Wrap Content Android图像高度超过环绕内容 Android
【发布时间】:2020-02-23 11:34:04
【问题描述】:

我正在使用 xamarin android 制作一个 android 应用程序,在该应用程序中我使用 cardview 和 recycler view。

问题

图片高度超过了文字的换行内容。

想要什么

我希望图像大小是文本覆盖的大小。

我的尝试:

我尝试将图像设置为线性布局的背景,但它设置的布局本身的高度比下图中显示的要大得多。 我已经尝试在 framelayout 中设置它,但它给出了与下面相同的结果

图片详情

数字随卡片视图的实例一起提供

1:图像的图像源高度正在增加视图高度

2:此图设置完美,因为原图高度分辨率低,图片被拉伸查看

3:再次图像高度分辨率高,因此视图被图像扩展

4,5 cardview 没有图片

我的代码:

<RelativeLayout
    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="wrap_content">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/cardView"
        app:cardBackgroundColor="@android:color/transparent">



        <ImageView
             android:layout_width="match_parent"
             android:layout_height="fill_parent"
             android:adjustViewBounds="true"
             android:scaleType="fitXY"
             android:id="@+id/cardImage"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/templateLayout"
            >

            <TextView
                android:text="Title:"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:id="@+id/listTitle"/>
            <TextView
                android:text="Start Time:"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="15sp"
                android:id="@+id/listSTime"/>
            <TextView
                android:text="End Time:"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="15sp"
                android:id="@+id/listFTime"/>
            <TextView
                android:text="Description:"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="15sp"
                android:id="@+id/listDescription"/>


        </LinearLayout>


    </android.support.v7.widget.CardView>

</RelativeLayout>

图片:

【问题讨论】:

    标签: android layout android-recyclerview cardview


    【解决方案1】:

    将以下字段添加到 ImageView

    android:scaleType="centerCrop"
    android:adjustViewBounds="true"
    

    【讨论】:

      【解决方案2】:

      您可以将 imageView 属性更改为android:scaleType="centreCrop",并将高度更改为wrap content。在您的情况下,您将其与parent 匹配,它是卡片视图。而 textview 是线性布局。

      Orelse 你可以将ImageView 移动到textView 的相同线性布局

      【讨论】:

      • 哦,是的,你是对的,textview 在线性布局中,但是如果我添加 scaletype center crop 来简单地裁剪图像视图并且图像是部分可见的,如果我在线性布局中添加 imageview 那么文本将是在图像视图完成后渲染,如果我将其添加为线性布局的背景,它也会超过 textview 大小并且它也不支持 scaletype
      • 或者您可以将imageView 保留原样。将宽度和高度设置为 wrapcontent
      • 如果我对图像视图执行wrap_content 并添加分辨率较低的图像,则视图的其余部分将为空,如果我在将图像放入线性布局后执行此操作,那么其他视图将在 imageview 之后再次启动结束了
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-04
      • 1970-01-01
      • 2021-03-14
      • 2013-04-08
      • 1970-01-01
      • 2014-06-15
      相关资源
      最近更新 更多