Home > Enterprise >  How to make an image always have the same height as another view?
How to make an image always have the same height as another view?

Time:10-27

How can I make the image (the actual image itself, not just ImageView) always have the same height as LinearLayout?

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent">

            <ImageView
                android:id="@ id/image"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:src="@drawable/myimage"/>

            <LinearLayout
                android:id="@ id/textview_layout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@ id/tv2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>

                <TextView
                    android:id="@ id/tv2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </androidx.constraintlayout.widget.ConstraintLayout>

CodePudding user response:

May be this will help you as per your question

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@ id/image"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:contentDescription="@string/app_name"
        android:src="@drawable/ic_launcher_foreground"
        app:layout_constraintBottom_toBottomOf="@ id/textview_layout"
        app:layout_constraintTop_toTopOf="@ id/textview_layout" />

    <LinearLayout
        android:id="@ id/textview_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@ id/tv2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." />

        <TextView
            android:id="@ id/tv3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." />

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
  • Related