【问题标题】:How do I properly set text onto a dynamically loaded image?如何在动态加载的图像上正确设置文本?
【发布时间】:2014-11-11 06:49:52
【问题描述】:

我有一个自定义数组适配器,其中每个项目由一个图像视图上的两个文本视图组成(SmartImageView 是第三方图像视图,可以从 url 呈现远程图像):

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

<com.loopj.android.image.SmartImageView
    android:id="@+id/backgroundImage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<RelativeLayout
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:text="Data Model Title"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/details"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/title"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:text="Data Model Details"
        android:textSize="15sp" />
</RelativeLayout>
</FrameLayout>

我看到的图像有上下边距,没有文字:

1) 带有文本的 RelativeLayout 应该覆盖图像,因为它是 FrameLayout 的第二个孩子

2) 为什么我的图片上下都有边距?我说我的 imageview 的尺寸与父级匹配,并且没有为其指定任何顶部或底部边距

【问题讨论】:

    标签: android android-framelayout


    【解决方案1】:
    1. 应该而且确实如此。由于其他原因,文本未显示。
    2. 我添加了 android:scaleType="centerCrop" ,它完全填满了该行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 2016-06-08
      • 2018-02-11
      相关资源
      最近更新 更多