English 中文(简体)
图像“固定”位置上的文本视图
原标题:android position TextView on "fixed" position on image

I m trying to display values that a user enters on an image, there are 4 versions of image (ldpi, mdpi, hdpi and xhdpi). I want to position the textViews on a "fixed" location that adjusts to the right screensize.

有没有人建议我如何实现这个目标?

这是我要做的事的草图

< a href=" "http://dl.dropbox.com/u/251/053/stackoverflow.png" rel="nofollow" >http://dl.dropbox.com/u/251/053/stackoverflow.png

edit

Thanks for the fast responses. Uploaded a new image, this isn t possible with relative layout I guess?

http://dl.droppox.com/u/251/053/stackoverflow1.png

最佳回答

查看“实时拉尤特”文件:http://developer.android.com/reference/android/widget/RelativeLayoot.html

您可以将您的文本View 围绕您的图像View 。

问题回答

解决这个问题的最佳方式是建立自定义版面, 期望图像视图成为第一个孩子。

其它所有的孩子 都将是文本视图 您也可以:

  • position relatively to the position of your ImageView
  • position proportionally to the height/width of your parent custom layout that matches the height/width of your ImageView

儿童文本查看 s 的左/上方位置信息可以通过适合您需要的自定义版式Params 类来提供 。

我认为最好的方法是通过扩展“ 视图” 类来创建自定义视图。 它不那么复杂 。 < a href=" http:// developmenter.android.com/guide/potics/ ui/ customis- particults. html" rel=“ nofollow” >这里 您可以找到更多关于自定义 UI 组件的信息 。

The main idea is to override onDraw(Canvas canvas) and onMeasure(int widthMeasureSpec, int heightMeasureSpec) methods. In onMeasure you should return the dimensions of your view and also you may calculate the size and angle of the rectangle and also the size of text you want to draw. Or you can implement custom resize() method that will be called explicitly on you view from the activity and make text and image calculations.

当您知道所有测量数据时, 您可以在 Draw( Canvas corrack) 方法中定位并绘制图像和文字 。

@Override
    protected void onDraw(Canvas canvas) {

    myImageDrawable.setBounds(0,0,50,50);
    myImageDrawable.draw(canvas);

    canvas.drawText(myText, 10, 10, myTextPaint);
}

You can find more info about Canvas class here. Also you may use StaticLayout to measure text.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签