【问题标题】:Forcing image to be cropped to wrap content强制裁剪图像以包装内容
【发布时间】:2015-03-09 00:24:39
【问题描述】:

我有一个Dialog,我将布局设置为我创建的自定义布局。我要做的是使背景图像(在本例中为 ImageView)裁剪为覆盖 TextView 内容空间所需的内容。这是现在的样子:

但我需要的是在 TextView 的“内容”行之后切断背景图像。我不确定这样做的方法。我发现的唯一方法是硬编码 RelativeLayout 高度(即 200dp),但 TextView 的内容将是动态的并且会增长/缩小,所以这对我来说不是一个解决方案。有任何想法吗?谢谢

这是此布局的 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        android:src="@drawable/blue9" >
    </ImageView>

    <TextView
        android:id="@+id/tvMessage"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvTitle"
        android:layout_marginTop="5dp"
        android:gravity="center"
        android:textColor="#FFF"
        android:text="This \n is \n my \n content"
        android:textSize="20sp" />

</RelativeLayout>

此外,当我将 RelativeLayout 的背景设置为可绘制对象时,也会发生相同的效果。我希望 ImageView 上的 scaleType 属性会有所帮助。

【问题讨论】:

  • 从布局和用户文本视图背景中删除图像视图以用于背景可绘制

标签: java android xml android-layout


【解决方案1】:

我相信您应该能够将 TextView 的背景属性设置为可绘制对象。

【讨论】:

    猜你喜欢
    • 2011-01-01
    • 2016-07-22
    • 2013-01-08
    • 1970-01-01
    • 2018-02-11
    • 2017-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多