繁体   English   中英

TextView和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.

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