Android 在水平线性布局中设置图像视图的高度

Android 在水平线性布局中设置图像视图的高度,android,Android,我有一个带有ImageView和TextView的水平线性布局。我的课文长度可以不同。因此,我希望ImageView与TextView具有相同的高度。有谁能告诉我如何实现这一点吗?您可以借助RelativeLayout实现这一点,只需将imageview的alignTop和alignBottom属性设置为textview即可。试试这个 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http

我有一个带有ImageView和TextView的水平线性布局。我的课文长度可以不同。因此,我希望ImageView与TextView具有相同的高度。有谁能告诉我如何实现这一点吗?

您可以借助RelativeLayout实现这一点,只需将imageview的alignTop和alignBottom属性设置为textview即可。

试试这个

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextViewsdfljasldfjl ;kasjdflkajslkdfasdfjlasjdfklasdklfjlkasdflkasdlkflkasdfasdfasdfasdfasdfasdf" />
    </LinearLayout>
</LinearLayout>