简体   繁体   English

如何在Android中设置视图的X位置

[英]How to set the x position of views in android

I am creating a number of imageviews and textviews on runtime depending on the objects in my webservice. 我在运行时根据Web服务中的对象创建了许多图像视图和文本视图。 I'm creating linearLayout horizontal and adding imageviews and textviews to layout, now the issue is the text are against images, and images are of different width so i want to set x position of my textviews so they all look align how can this be done, 我正在水平创建linearLayout并向布局中添加imageviews和textviews,现在的问题是文本是针对图像的,并且图像的宽度不同,因此我想设置textview的x位置,以便它们看起来都对齐。 ,

i tried absolutelayout(warning deprecated) , setx(no method showed) 我尝试了absolutelayout(不建议使用警告),setx(未显示任何方法)

I presume you mean this is a vertical LinearLayout, and each text/image combo is added below the previous one? 我想您的意思是这是一个垂直的LinearLayout,并且每个文本/图像组合都被添加到前一个的下面吗? In that case, you could have two LinearLayouts next to each other like two columns, adding the images to one and the text fields to the other. 在这种情况下,您可以像两个列一样使两个LinearLayout彼此相邻,将图像添加到一个,将文本字段添加到另一个。 Then the widest image would stretch its layout to that width and all text fields would be just to the right of it. 然后,最宽的图像会将其布局扩展到该宽度,并且所有文本字段都将在其右侧。

您可以在运行时使用基于面板高度和宽度调整大小的图像来在运行时视图上调整图像的大小。此堆栈溢出线程调整图像java getScaledInstance的大小

在ImageView和TextView中使用weight属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM