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

Таким образом, моя кнопка и редактируемые текстовые виджеты продолжают толкаться вверх, когда я динамически добавляю текстовые представления в мое представление прокрутки.Таким образом, высота прокрутки также увеличивается.Как мне убедиться, что представление прокрутки исправлено, я посмотрел на похожие вопросы и попытался реализовать его, но не работал.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:windowSoftInputMode="stateVisible|adjustPan"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/name"
        android:hint="Enter name"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.25"/>

    <EditText
        android:id="@+id/phone_num"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.25"
        android:hint="Enter Phone Number"/>

    <Button
        android:id="@+id/submit"
        android:layout_width="150dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:text="@string/submit_contact"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:isScrollContainer="false"
        android:fillViewport="true">

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

    </ScrollView>

</LinearLayout>

1 Ответ

0 голосов
/ 05 апреля 2019

Попробуйте установить для всех высот значение 0dp и присвойте wheightSum родительскому представлению.Чтобы иметь фиксированную высоту кнопки, окружите ее LinearLayout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:windowSoftInputMode="stateVisible|adjustPan"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="2.75"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/name"
        android:hint="Enter name"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.25"/>

    <EditText
        android:id="@+id/phone_num"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.25"
        android:hint="Enter Phone Number"/>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.25"
        android:orientation="vertical">

        <Button
            android:id="@+id/submit"
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:layout_gravity="center"
            android:text="test"/>
        
    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:isScrollContainer="false"
        android:fillViewport="true">

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

    </ScrollView>

</LinearLayout>

Попробуйте, если это не сработает, вы можете опубликовать то, что вы уже пробовали, и код, как вы динамически рекламируете textViews.Удачи

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...