在ImageView的顶级Android中放置一个TextView [英] Placing a textview on top of imageview in android

查看:110
本文介绍了在ImageView的顶级Android中放置一个TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 在我有一个列表视图,有一个的ImageView 这是 滚动垂直
  • 在我试图把一个的TextView ImageView的顶部
  • 双方的意见必须是可见
  • I have a listview, that has a single imageview which is scrollable vertically
  • I am trying to place a textview on top of Imageview
  • Both the views must be visible
  1. 这可能吗?
  2. 如果是,如何以编程方式做到这一点?
  3. 我应该需要什么样的变化使?

list_view_item_for_images.xml


list_view_item_for_images.xml

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

    <ImageView
        android:id="@+id/flag"
        android:layout_width="fill_parent"
        android:layout_height="250dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

这使象下面这样的输出

It gives a output like below

如何做类似下面

请注意::盘1安培; 2是textviews

note :: Dish 1 & 2 are textviews

推荐答案

这应该给你所需的布局:

This should give you the required layout:

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

    <ImageView
        android:id="@+id/flag"
        android:layout_width="fill_parent"
        android:layout_height="250dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="20dp"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

玩安卓layout_marginTop =20dp,看看哪一个更适合你。使用ID 的TextView 动态设置的android:文本

Play with android:layout_marginTop="20dp" to see which one suits you better. Use the id textview to dynamically set the android:text value.

由于RealativeLayout栈的孩子,确定TextView的ImageView的把它过度的ImageView的后。

Since a RealativeLayout stacks its children, defining the TextView after ImageView puts it 'over' the ImageView.

注意:类似的结果,可以使用达到了的FrameLayout 作为父母,伴随着效率提升了使用的任何其他Android容器。由于伊戈尔Ganapolsky (见下面的注释)指出,这个答案需要更新。

NOTE: Similar results can be attained using a FrameLayout as the parent, along with the efficiency gain over using any other android container. Thanks to Igor Ganapolsky(see comment below) for pointing out that this answer needs an update.

这篇关于在ImageView的顶级Android中放置一个TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆