does minHeight do anything?

后端 未结 3 1445
悲&欢浪女
悲&欢浪女 2021-02-06 22:16

In the attached image, I want the column of buttons to match the height of the image, but I also want there to be a minimum height for the column of buttons.

It correctl

相关标签:
3条回答
  • 2021-02-06 22:43

    Although my other answer is still valid, nowadays we have the benefit of ConstraintLayout. I'm sure the original poster has long since gotten past this problem, but for future users' sake: you can achieve the same result without the extra layer of ViewGroups. Something like this:

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="150dp">
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:text="Button1"
            app:layout_constraintBottom_toTopOf="@+id/button2"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:text="Button2"
            app:layout_constraintBottom_toTopOf="@+id/button3"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/button1" />
    
        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:text="Button3"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/button2" />
    
        <android.support.constraint.Barrier
            android:id="@+id/barrier"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:barrierDirection="end"
            app:constraint_referenced_ids="button1,button2,button3" />
    
        <ImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="@id/barrier"
            app:layout_constraintTop_toTopOf="parent" />
    </android.support.constraint.ConstraintLayout>
    

    Possibly you may need something like:

        app:layout_constrainedWidth="true"
    

    for the ImageView to handle larger images, but I haven't tested it.

    0 讨论(0)
  • 2021-02-06 22:53

    I don't know all your exact requirements, but it seems you can solve this with another layer pretty much like in your diagram. Set the minHeight on an outer layout and then just fill_parent/match_parent on the inside. Maybe something like:

    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:minHeight="150dp">
        <LinearLayout
            android:orientation="vertical"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content">
        </LinearLayout>
        <ImageView />
    </LinearLayout>
    
    0 讨论(0)
  • 2021-02-06 22:56

    Tricky question because it calls TextView.setMinHeight — but then you are not using a TextView.

    So generally android:minHeight does indeed do something but not in your particular case.

    0 讨论(0)
提交回复
热议问题