簡體   English   中英

如何設置列表視圖的最大高度

[英]How to set the max height of a list view

屏幕上有3個垂直部分:

  1. 一些文字
  2. 列表顯示
  3. 其他一些文本字段

我不明白為什么列表視圖中有更多元素時,它將整個屏幕移到底部,而沒有為第3部分留出位置,並使第3部分無法訪問且不可見。

<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
    android:layout_height="wrap_content"
    tools:context="com.transport.ScreenDelivery">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:gravity="center_vertical"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

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

            <TextView
                android:id="@+id/textView_customer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
        </LinearLayout>

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

            <ListView
                android:id="@+id/listView_pallets"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>

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

            <TextView
                android:id="@+id/textView_signature"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
        </LinearLayout>
    </LinearLayout>
</android.support.constraint.ConstraintLayout>

我相信您只能使用約束布局並完全刪除線性布局才能找到解決方案,但是我對ConstraintLayout的了解不足。 但是,您可以權衡最外層LinearLayout內部的元素。 例如,將android:weightSum="3"分配給最外面的LinearLayout,然后將android:layout_weight="1"分配給內部元素(在您的情況下為其他LinearLayouts)

干得好

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="com.transport.ScreenDelivery">

    <LinearLayout
        android:id="@+id/bottom_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">

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

            <TextView
                android:id="@+id/textView_expectedSum"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:paddingBottom="5dp"
                android:paddingTop="5dp"
                android:text="Очаквана сума"
                android:textSize="16sp"
                tools:text="Очаквана сума" />

            <TextView
                android:id="@+id/textView_expectedSumNum"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:paddingBottom="5dp"
                android:paddingTop="5dp"
                android:text="-"
                android:textSize="16sp"
                tools:text="-" />

        </LinearLayout>

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

            <TextView
                android:id="@+id/textView_signature"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:paddingBottom="5dp"
                android:paddingTop="5dp"
                android:text="Подпис"
                android:textSize="16sp"
                tools:text="Подпис" />

            <TextView
                android:id="@+id/textView_signatureField"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:paddingBottom="5dp"
                android:paddingTop="5dp"
                android:textSize="16sp" />

        </LinearLayout>

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

            <TextView
                android:id="@+id/textView_returnSum"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:paddingBottom="5dp"
                android:paddingTop="5dp"
                android:text="Сума за връщане"
                android:textSize="16sp"
                tools:text="Сума за връщане" />

            <TextView
                android:id="@+id/_returnSumField"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:paddingBottom="5dp"
                android:paddingTop="5dp"
                android:textSize="16sp" />

        </LinearLayout>

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/textView_remarks"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingBottom="5dp"
                    android:paddingTop="5dp"
                    android:text="Бележка"
                    android:textSize="16sp"
                    tools:text="Бележка" />
            </LinearLayout>

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

                <Spinner
                    android:id="@+id/spinner_note"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:drawable/btn_dropdown"
                    android:spinnerMode="dropdown" />


                <EditText
                    android:id="@+id/editText_note"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint=""
                    android:inputType="text"
                    android:visibility="gone" />
            </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:baselineAligned="false"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/textView_image"
                    android:layout_width="269dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:paddingBottom="5dp"
                    android:paddingTop="5dp"
                    android:text="Снимка"
                    android:textSize="16sp"
                    tools:text="Снимка" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/button_takePhoto"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="150dp"
                    android:onClick="takePhoto"
                    android:text="Снимай"
                    tools:text="Снимай" />

                <ImageView
                    android:id="@+id/imageView_deliveryPhoto"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:contentDescription="Снимка на доставката"
                    android:maxHeight="200dp"
                    android:maxWidth="200dp"
                    android:minHeight="50dp"
                    android:minWidth="50dp"
                    app:srcCompat="?android:attr/alertDialogIcon" />
            </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:orientation="horizontal">

            <Button
                android:id="@+id/button_save"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Запази"
                tools:text="Запази" />

        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/top_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView_customer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Клиент"
            android:textSize="20sp"
            tools:text="Клиент" />

        <TextView
            android:id="@+id/textView_palletCount"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Брой палета"
            android:textSize="20sp"
            tools:text="Брой палета" />

        <TextView
            android:id="@+id/textView_palletCountNum"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="-"
            android:textSize="20sp"
            tools:text="-" />

    </LinearLayout>

    <ListView
        android:id="@+id/listView_pallets"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/bottom_layout"
        android:layout_below="@id/top_layout" />


</RelativeLayout>

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM