[英]ConstraintLayout: align top of textview with imageview
[英]TextView and ImageView do not top-align at the same level
我有一个非常简单的水平LinearLayout
,其中包含一个ImageView
和一个TextView
并且layout_gravity
都设置为top
。 两个视图的确确实在布局的顶部对齐,但是TextView
总是稍低一些,为了与ImageView
对齐,我必须给它一个负的layout_marginTop
。
我在这里想念什么吗?
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.67"
android:layout_gravity="top"
android:layout_margin="16dp"
android:textSize="16sp"
android:text="This is some text\nwith several\nline breaks"/>
<ImageView
android:id="@+id/card_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:layout_gravity="top"
android:layout_margin="16dp"
android:src="@drawable/placeholder"/>
</LinearLayout>
代替android:layout_height="wrap_content"
进行textview尝试使用android:layout_height =“ match_parent”并将其gravity
设置为top
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.