简体   繁体   English

相对于它旁边的视图垂直居中视图

[英]Center View vertically in relation to the Views next to it

Given the layout below:鉴于以下布局:

基地布局

I wanted to know if it's possible to center vertically the ImageView on the left in relation to the views on the right so that, if any of the labels grow, the ImageView would still be on the center (left image) and not on top (right image).我想知道是否可以将左侧的ImageView相对于右侧的视图垂直居中,这样,如果任何标签增长, ImageView仍将位于中心(左图)而不是顶部(右图)。

所需的布局 布局错误

I tried constraining the ImageView 's top to the upper label and its bottom to the lower label but I haven't been able to se in a way that autolayout would try to "satisfy both".我尝试将ImageView的顶部约束到上标签,将其底部约束到下标签,但我无法以自动布局尝试“同时满足两者”的方式进行设置。 Trying to change any priority or changing the constraint to a inequality only makes the ImageView goes up or down.尝试更改任何优先级或将约束更改为不等式只会使ImageView上升或下降。

Pretty sure you really mean Vertically not Horizontally ?很确定你真的是指垂直而不是水平

Embed your two labels into a Vertical stack view, and constrain the image view centered to the stack view.将您的两个标签嵌入到垂直堆栈视图中,并将图像视图限制在堆栈视图的中心。

Alternatively, for even fewer constraints needed...或者,对于需要更少的约束......

  • Embed your two labels into a Vertical stack view将您的两个标签嵌入到垂直堆栈视图中
  • Embed the image view and that "labels stack view" into a Horizontal stack view将图像视图和“标签堆栈视图”嵌入到水平堆栈视图中
  • set the Alignment of the Horizontal stack view to Center将水平堆栈视图的对齐设置为居中

在此处输入图像描述

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

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