android怎样将textview置于imageview之上

如题所述

使用FrameLayout 这个布局是一层一层叠放的
先放个imageview 然后再放一个textview即可
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-12-06
目前看来有三种方法可以实现
1. framelayout, a framelayout is used to stack a TextView on top of an ImageView
Java代码
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"

android:scaleType="center"
android:src="@drawable/golden_gate" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_gravity="center_horizontal|bottom"

android:padding="12dip"

android:background="#AA000000"
android:textColor="#ffffffff"

android:text="Golden Gate" />

</FrameLayout>

2. TextView on Canvas。 和framelayout不同,Canvas不是继承自ViewGroup,它不可以添加child views,所以你需要使用drawBitmap和drawText方法去实现

3. 使用merge tag,方法大致和framelayout一样
Java代码
<?xml version="1.0" encoding="utf-8"?>
<!--<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
--><merge xmlns:android="http://schemas.android.com/apk/res/android">

<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"

android:scaleType="center"
android:src="@drawable/mini" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="12dip"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#ffff0000"

android:text="Mini-Countryman" />

</merge>
<!--</LinearLayout>
-->

具体与framelayout区别参考 http://developer.Android.com/resources/articles/layout-tricks-merge.html


2


0
上一篇android中的matrix的简单应用
下一篇建立自己的TextView和ImageView的组合View类
我的同类文章
Android开发(1715) Android UI(812)
猜你在找

查看评论
1楼 xzpfengxi2016-08-29 21:34发表 [回复]

谢谢
您还没有登录,请[登录]或[注册]
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
核心技术类目
全部主题 Hadoop AWS 移动游戏 Java Android iOS Swift 智能硬件 Docker OpenStack VPN Spark ERP IE10 Eclipse CRM JavaScript 数据库 Ubuntu NFC WAP jQuery BI HTML5 Spring Apache .NET API HTML SDK IIS Fedora XML LBS Unity Splashtop UML components Windows Mobile Rails QEMU KDE Cassandra CloudStack FTC coremail OPhone CouchBase 云计算 iOS6 Rackspace Web App SpringSide MaemoCompuware 大数据 aptech Perl Tornado Ruby Hibernate ThinkPHP HBase Pure Solr Angular Cloud Foundry Redis Scala Django Bootstrap
个人资料

一叶飘舟本回答被提问者采纳