0

我正在使用 xamarin android 制作一个 android 应用程序,在该应用程序中我使用 cardview 和回收器视图。

问题

图像高度超过文本的换行内容。

想要什么

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

我试过的:

我尝试将图像设置为线性布局的背景,但它设置的布局本身的高度比下图中显示的要大得多。我已经尝试在 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>

图片:

在此处输入图像描述

在此处输入图像描述

4

2 回答 2

3

将以下字段添加到 ImageView

android:scaleType="centerCrop"
android:adjustViewBounds="true"
于 2020-05-08T03:10:52.003 回答
1

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

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

于 2019-10-28T07:33:52.863 回答