我在线性布局中的滚动视图将其上方的其他小部件向上推

时间:2019-04-05 14:36:55

标签: java android xml android-scrollview

因此,当我向滚动视图中动态添加文本视图时,我的按钮和编辑文本窗口小部件会不断向上推。因此,scrollview的高度也被提高了。我该如何确保滚动视图已修复,我已经研究过类似的问题并尝试实现它,但无法正常工作。

\usepackage[utf8]{inputenc}

1 个答案:

答案 0 :(得分:0)

尝试将所有高度设置为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的代码。祝你好运