android怎样将textview置于imageview之上

简介:

http://allenshao.iteye.com/blog/867581


目前看来有三种方法可以实现

1. framelayout, a framelayout is used to stack a TextView on top of an ImageView

Java代码   收藏代码
  1. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:layout_width="fill_parent"  
  3.     android:layout_height="fill_parent">  
  4.   
  5.     <ImageView    
  6.         android:layout_width="fill_parent"   
  7.         android:layout_height="fill_parent"   
  8.       
  9.         android:scaleType="center"  
  10.         android:src="@drawable/golden_gate" />  
  11.       
  12.     <TextView  
  13.         android:layout_width="wrap_content"   
  14.         android:layout_height="wrap_content"   
  15.         android:layout_marginBottom="20dip"  
  16.         android:layout_gravity="center_horizontal|bottom"  
  17.   
  18.         android:padding="12dip"  
  19.           
  20.         android:background="#AA000000"  
  21.         android:textColor="#ffffffff"  
  22.           
  23.         android:text="Golden Gate" />  
  24.   
  25. </FrameLayout>  

 

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

 

3. 使用merge tag,方法大致和framelayout一样

Java代码   收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <!--<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7. --><merge xmlns:android="http://schemas.android.com/apk/res/android">  
  8.   
  9.     <ImageView    
  10.         android:layout_width="fill_parent"   
  11.         android:layout_height="fill_parent"   
  12.       
  13.         android:scaleType="center"  
  14.         android:src="@drawable/mini" />  
  15.       
  16.     <TextView  
  17.         android:layout_width="wrap_content"   
  18.         android:layout_height="wrap_content"   
  19.         android:layout_gravity="center"  
  20.         android:padding="12dip"  
  21.         android:textSize="20sp"  
  22.         android:textStyle="bold"  
  23.         android:textColor="#ffff0000"  
  24.           
  25.         android:text="Mini-Countryman" />  
  26.   
  27. </merge>  
  28. <!--</LinearLayout>  
  29. -->  

 

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


相关文章
|
11月前
|
XML 前端开发 Android开发
Android:UI:Drawable:View/ImageView与Drawable
通过本文的介绍,我们详细探讨了Android中Drawable、View和ImageView的使用方法及其相互关系。Drawable作为图像和图形的抽象表示,提供了丰富的子类和自定义能力,使得开发者能够灵活地实现各种UI效果。View和ImageView则通过使用Drawable实现了各种图像和图形的显示需求。希望本文能为您在Android开发中使用Drawable提供有价值的参考和指导。
241 2
|
Android开发
Android经典实战之Textview文字设置不同颜色、下划线、加粗、超链接等效果
本文介绍了 `SpannableString` 在 Android 开发中的强大功能,包括如何在单个字符串中应用多种样式,如颜色、字体大小、风格等,并提供了详细代码示例,展示如何设置文本颜色、添加点击事件等,助你实现丰富文本效果。
897 4
|
12月前
|
XML 存储 Java
浅谈Android的TextView控件
浅谈Android的TextView控件
109 0
|
Java Android开发 Kotlin
Android项目架构设计问题之要在Glide库中加载网络图片到ImageView如何解决
Android项目架构设计问题之要在Glide库中加载网络图片到ImageView如何解决
134 0
|
Java Android开发
18. 【Android教程】图片控件 ImageView
18. 【Android教程】图片控件 ImageView
252 4
|
XML IDE 开发工具
13. 【Android教程】文本框 TextView
13. 【Android教程】文本框 TextView
246 2
|
Android开发
android TextView HTML 的效果
android TextView HTML 的效果
83 2
|
编解码 Android开发
Android 解决TextView多行滑动与NestedScrollView嵌套滑动冲突的问题
Android 解决TextView多行滑动与NestedScrollView嵌套滑动冲突的问题
370 0
|
XML Java Android开发
Android控件之基础控件——进度条类的view——TextView、Checkbox复选控件、RadioButton单选控件、ToggleButton开关、SeekBar拖动条、menu、弹窗
Android控件之基础控件——进度条类的view——TextView、Checkbox复选控件、RadioButton单选控件、ToggleButton开关、SeekBar拖动条、menu、弹窗
1204 1
|
XML 搜索推荐 Java
Android TextView的字体设置
【5月更文挑战第13天】
763 0

热门文章

最新文章