线性布局maxHeight为什么不起作用? [英] Why doesn't Linear Layout maxHeight work?

查看:204
本文介绍了线性布局maxHeight为什么不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的布局.

我在线性布局上设置了最大和最小高度,但是最大高度似乎不起作用.实际上,如果 TextView R.id.testo 包含大量文本,则不会进行修剪.如果我设置固定高度,则不会发生这种情况.但是我不想设置一个固定的高度,以使其在选择例如溢出屏幕模式时能够正确调整其大小.

I set max and min height on the linear layout but max height seems not to be working. In fact if TextView R.id.testo has a lot of text this won't be trimmed. This doesn't happen if I set fixed height. But I didn't want to set a fixed height in order to make it correctly resizable when for instance spilt screen mode is selected.

<androidx.constraintlayout.widget.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="match_parent"
tools:context=".WidgetSettingsActivity">

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@android:color/transparent"
    android:elevation="0dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:popupTheme="?attr/popupThemeToolbar"
    app:title=""
    app:titleTextAppearance="@style/ToolbarTitle" />

<LinearLayout
    android:id="@+id/card"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="55dp"
    android:layout_marginTop="@dimen/margin_16"
    android:layout_marginEnd="55dp"
    android:background="@drawable/widget_background"
    android:clickable="false"
    android:maxHeight="400dp"
    android:minHeight="400dp"
    android:orientation="vertical"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/toolbar">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/titolo"
            style="@style/Base.TextAppearance.AppCompat.Title"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:layout_weight="1"
            android:drawableEnd="@drawable/ic_if_settings_1540178"
            android:ellipsize="end"
            android:fontFamily="@font/encodesanscondensed_medium"
            android:hint="@string/no_title"
            android:maxLines="1"
            android:padding="8dp"
            android:textSize="18sp"
            tools:text="Title" />

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingStart="@dimen/fab_margin"
            android:paddingTop="4dp"
            android:paddingEnd="@dimen/fab_margin"
            android:paddingBottom="4dp">

            <TextView
                android:id="@+id/testo"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="@font/encodesanscondensed_regular"
                android:hint="@string/no_text"
                android:textColor="?android:attr/editTextColor"
                android:textSize="18sp"
                tools:text="Text multiple rows" />

            <TextView
                android:id="@+id/last_modified"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="end|bottom"
                android:layout_marginTop="24dp"
                android:fontFamily="@font/encodesanscondensed_regular"
                android:gravity="end|bottom"
                android:textSize="12sp"
                tools:text="@string/last_modified_s" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="35dp"
    android:layout_marginEnd="35dp"
    android:layout_marginBottom="8dp"
    android:gravity="bottom"
    android:orientation="vertical"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/card"
    app:layout_constraintVertical_bias="0.905">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="13dp"
        android:layout_marginBottom="@dimen/margin_16"
        android:fontFamily="@font/encodesanscondensed_medium"
        android:text="@string/background_transparency"
        android:textAllCaps="true"
        android:textColor="@color/colorPrimary"
        android:textSize="13sp" />

    <androidx.appcompat.widget.AppCompatSeekBar
        android:id="@+id/seekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="255"
        android:min="0"
        android:progressBackgroundTint="@color/white_opacity" />
</LinearLayout>

推荐答案

因为您的父视图是 ConstraintLayout .

我还为我实现了max和min

I have also implemented the max and min and for me

替换这些行

android:maxHeight="400dp"
android:minHeight="400dp"

使用

app:layout_constraintHeight_max="400dp"
app:layout_constraintHeight_min="400dp"
app:layout_constrainedHeight="true"

此代码工作正常.我希望它也对您有用.

This code working fine. I hope it also works for you.

这篇关于线性布局maxHeight为什么不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆