如何将ImageView和TextView集中在一起?

时间:2011-09-12 17:47:45

标签: android android-layout

我需要使用一起居中的ImageView和TextView制作标题,如下图所示。

--------------------------------
|                              |
|    ----------- ----------    |
|    -ImageView- -TextView-    |
|    ----------- ----------    |
|                              |
|       -Other Content-        |
|                              |

必须将ImageView缩放到TextView的高度,并且它们必须一起居中,就好像它们是一个小部件一样。关于如何实现这一目标的任何想法?

3 个答案:

答案 0 :(得分:2)

EDIT: you can use TableLayout for it, put the textview and Imagview in 2 columns of tablerow, then your imageview is adjust acccording to your textview's columns height.

use your textview's height as wrap_content and imageview's height fill_parent

答案 1 :(得分:1)

如果它们必须看起来像一个小部件,那么用水平LinearLayout包装它们,并且实际上将它视为单个小部件。将这个新的“小部件”集中在一起可以达到你想要的效果。

答案 2 :(得分:0)

使用RelativeLayout。将ImageView的顶部和底部与TextView的顶部和底部对齐。设置textview的上边距。在父布局中将中心水平设置为true。