热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在安卓系统的imageview顶部放置一个textview-Placingatextviewontopofimageviewinandroid

Ihavealistview,thathasasingleimageviewwhichisscrollablevertically我有一个listview,只有一个i
  • I have a listview, that has a single imageview which is scrollable vertically
  • 我有一个listview,只有一个imageview可以垂直滚动
  • I am trying to place a textview on top of Imageview
  • 我想在Imageview的顶部放置一个textview
  • Both the views must be visible
  • 两个视图都必须是可见的

  1. Is it possible ?
  2. 是可能的吗?
  3. If yes, How to do it programmatically ?
  4. 如果是,如何以编程方式进行?
  5. What changes should i need to make ?
  6. 我需要做什么改变?

list_view_item_for_images.xml

list_view_item_for_images.xml




    


It gives a output like below

输出如下所示

enter image description here

How to do something like below

如何做如下的事情

enter image description here

note :: Dish 1 & 2 are textviews

注意:Dish 1 & 2是textviews

7 个解决方案

#1


78  

This should give you the required layout:

这将给您所需的布局:




    

    


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

使用android:layout_marginTop=“20dp”,看看哪个更适合您。使用id textview来动态设置android:文本值。

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

由于RelativeLayout叠加了其子元素,所以在ImageView后定义TextView会将其置于ImageView之上。

NOTE: Similar results can be obtained 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.

注意:类似的结果可以使用FrameLayout作为父程序,以及使用其他任何android容器的效率提高。感谢Igor Ganapolsky指出,这个答案需要更新。

#2


8  

Try this:

试试这个:






Hope this could help you.

希望这能对你有所帮助。

#3


6  

you can use framelayout to achieve this.

您可以使用framelayout来实现这一点。

how to use framelayout

如何使用framelayout


ref: tutorialspoint

裁判:tutorialspoint

#4


0  

just drag and drop the TextView over ImageView in eclipse

在eclipse中,只需将TextView拖放到ImageView上








And this the output the above xmlenter image description here

输出上面的xml

#5


0  

As you mentioned in OP, you need to overlay Text on ImageView programmatically way. You can get ImageView drawable and write on it with the help of putting it on Canvas and Paint.

正如您在OP中提到的,您需要以编程方式在ImageView上覆盖文本。您可以获得ImageView drawable,并通过将它放在Canvas和Paint的帮助在上面进行编写。

 private BitmapDrawable writeTextOnDrawable(int drawableId, String text) 
 {
 Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true);
 Typeface tf = Typeface.create("Helvetica", Typeface.BOLD);
 Paint paint = new Paint();
 paint.setStyle(Style.FILL);
 paint.setColor(Color.WHITE);
 paint.setTypeface(tf);
 paint.setTextAlign(Align.CENTER);
 paint.setTextSize(11);
 Rect textRect = new Rect();
 paint.getTextBounds(text, 0, text.length(), textRect);
 Canvas canvas = new Canvas(bm);
 canvas.drawText(text, xPos, yPos, paint);
 return new BitmapDrawable(getResources(), bm);
 }

#6


0  

you can try this too. I use just framelayout.

你也可以试试这个。我使用framelayout。

 

#7


-1  

Maybe you should just write the ImageView first and the TextView second. That can help sometimes. That's simple but I hope it helps somebody. :)

也许你应该先写ImageView然后再写TextView。有时可以帮助。这很简单,但我希望它能帮助别人。:)


推荐阅读
author-avatar
mobiledu2502878013
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有