Scrollview не показывает последний элемент в макете - PullRequest
0 голосов
/ 05 января 2019

Вот код, который я столкнулся с проблемой, я взял 2 линейных макета в представлении прокрутки, теперь последняя кнопка во 2-м линейном макете скрыта, или я могу сказать, что не отображается должным образом.

Вот снимок экрана. Вы можете проверить, что выбранная область является кнопкой, но не работает должным образом.

enter image description here

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    >

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

        <LinearLayout
            android:id="@+id/ConcernedPortionofScreen"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.25"
            android:orientation="vertical">
        </LinearLayout>

        <LinearLayout
            android:id="@+id/RestofScreen"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.75"
            android:orientation="vertical"
            android:padding="20dp">               

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/custom_button_shape_with_bg_primary"
                android:minHeight="@dimen/minimum_height_all_object"
                android:layout_marginTop="@dimen/add_child_rquest_margin_top"
                android:text="SELECT"
                android:textColor="@color/white"
                />
        </LinearLayout>

    </LinearLayout>
</ScrollView>

когда я пытаюсь удалить layout_weight, мой макет становится массовым.

enter image description here

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

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

            <LinearLayout
                android:id="@+id/ConcernedPortionofScreen"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.25"
                android:orientation="vertical">

                <!-- Parent FrameLayout 'FL' -->
                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <!--Conitans Tree Childs -->

                </FrameLayout>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/RestofScreen"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.75"
                android:orientation="vertical"
                android:padding="20dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:weightSum="1">

                    <!--Conitans Two Childs -->

                </LinearLayout>


                <EditText
                    style="@style/CustomEdittextTheme"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/add_child_rquest_margin_top"
                    android:hint="Enter Child Name"
                    android:minHeight="@dimen/add_child_rquest_minimum_height_all_object" />

                <EditText
                    style="@style/CustomEdittextTheme"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/add_child_rquest_margin_top"
                    android:hint="Select City"
                    android:minHeight="@dimen/add_child_rquest_minimum_height_all_object" />

                <TextView
                    style="@style/CustomEdittextTheme"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/add_child_rquest_margin_top"
                    android:hint="Select Birthdate"
                    android:minHeight="@dimen/add_child_rquest_minimum_height_all_object" />

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

                    <!--Conitans Two Childs -->

                </LinearLayout>

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

                    <!--Conitans Two Childs -->

                </LinearLayout>


                <EditText
                    style="@style/CustomEdittextTheme"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/add_child_rquest_margin_top"
                    android:hint="Enter Mobile Number"
                    android:minHeight="@dimen/add_child_rquest_minimum_height_all_object" />

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

                    <!--Conitans Two Childs -->

                </LinearLayout>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/add_child_rquest_margin_top"
                    android:fontFamily="@font/segoe_ui_bold"
                    android:paddingLeft="10dp"
                    android:text="Note / Message :"
                    android:textColor="@color/colorPrimaryDark"
                    android:textSize="18dp" />

                <EditText
                    style="@style/CustomEdittextTheme"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/add_child_rquest_margin_top"
                    android:inputType="textMultiLine"
                    android:lines="8"
                    android:maxLines="8"
                    android:minHeight="@dimen/add_child_rquest_minimum_height_all_object"
                    android:minLines="8"
                    android:scrollbars="vertical" />


                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="@dimen/add_child_rquest_margin_top"
                    android:background="@drawable/custom_button_shape_with_bg_primary"
                    android:fontFamily="@font/segoe_ui_bold"
                    android:minHeight="@dimen/add_child_rquest_minimum_height_all_object"
                    android:text="SUBMIT"
                    android:textColor="@color/white" />
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</android.support.constraint.ConstraintLayout>

Ответы [ 2 ]

0 голосов
/ 08 января 2019

Ребята, я только что удалил Main Linear_layout, и теперь он работает хорошо.

Спасибо, ребята, что ответили.

Вот код, который работает для меня.

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

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

            <!-- Part 1 [layout_weight='0.3' ] -->
            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                >

                <!-- Contains Childs -->

            </FrameLayout>

            <!-- Part 2 [layout_weight='0.7' ] -->
            <LinearLayout
                android:id="@+id/RestofScreen"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.75"
                android:orientation="vertical"
                android:padding="20dp">

                <!-- Contains All Childs -->

            </LinearLayout>

        </LinearLayout>

    </ScrollView>
</android.support.constraint.ConstraintLayout>
0 голосов
/ 05 января 2019

Это происходит из-за layout_height="match_parent" для ScrollView дочернего LinearLayout Изменить layout_height на wrap_content

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    >

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

    //childs ..........
    </LinearLayout>
<ScrollView>

wrap_content

Установка размера представления в wrap_content заставит его расширяться только настолько, чтобы содержать значения (или дочерние элементы управления), которые он содержит. Для элементов управления - таких как текстовые поля (TextView) или изображения (ImageView) - это обернет отображаемый текст или изображение. Для элементов макета он изменит размер макета так, чтобы он соответствовал элементам управления / макетам, добавленным в качестве его дочерних элементов.

Официальные документы говорят

  • FILL_PARENT (переименовано MATCH_PARENT в API уровня 8 и выше), что означает, что представление должно иметь вид big as its parent (минус заполнение)

  • WRAP_CONTENT, что означает, что представление хочет быть просто большим enough to enclose its content (плюс отступ)

...