android - 初学者 android 开发人员 - 布局有困难

标签 android layout button scrollview

我有一个位于 ScrollView 下方的按钮,该按钮设置为与父级底部对齐。 ScrollView 的高度设置为 wrap_content。一旦 ScrollView 被内容填充,它就会出现在按钮下方。如何将它设置为不在按钮后面,以便 ScrollView 在按钮开始时结束?

我试过将 android:layout_below 放在底部按钮中,当那不起作用时,我尝试在 ScrollView 中使用 layout_above对于按钮上方。最后一个导致我的应用程序在启动时崩溃,不知道为什么。第一个是当 ScrollView 比屏幕长时,它会导致按钮被放置在下方而无法访问它。

这是我的 XML 文件。

<RelativeLayout 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="@color/light_blue"
    android:padding="5dp"
    tools:context=".MainActivity" >

    <EditText
        android:id="@+id/editText_query"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/queryPromt"
        android:imeOptions="actionNext"
        android:inputType="text"
        android:textColor="#000" />

    <EditText
        android:id="@+id/editText_tag"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText_query"
        android:layout_marginTop="10dp"
        android:layout_toLeftOf="@+id/saveButton"
        android:hint="@string/tagPrompt"
        android:imeOptions="actionDone"
        android:inputType="text" />

    <Button
        android:id="@id/saveButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@id/editText_query"
        android:text="@string/save" />

    <TextView
        android:id="@+id/textView_taggedSearches"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignRight="@id/saveButton"
        android:layout_below="@id/saveButton"
        android:layout_marginTop="10dp"
        android:background="#666"
        android:gravity="center_horizontal"
        android:text="@string/taggedSearches"
        android:textColor="#FFF"
        android:textSize="18sp" />

    <ScrollView
        android:id="@+id/scrollView_query"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView_taggedSearches"
        android:padding="5dp" >

        <TableLayout
            android:id="@+id/tableLayout_query"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:stretchColumns="*" >
        </TableLayout>
    </ScrollView>

    <Button
        android:id="@+id/button_clearTags"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="@string/clearTags" />

</RelativeLayout>

最佳答案

尝试添加

android:layout_below="@id/scrollView_query"

到最后一个按钮

关于android - 初学者 android 开发人员 - 布局有困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13770215/

相关文章:

javascript - 将文本从 HTML 转换为 Javascript 作为输入更改 ID 的函数

android - 与整个项目共享嵌入式字体的最佳实践

Android: Material 设计中不存在的膨胀元素

ios - 如何实现用于大量文本输入的 UITextView 屏幕

html - 如何将按钮链接到另一个页面上带有 div 内容的选项卡?

python - 如何将 python 窗口保持在所有其他窗口之上(python 3.1)

android - 未发现 Activity 异常

java - 自定义 map 标记

java - 如何在窗口内移动 3 个按钮

当列表填满屏幕时,列表下方的 android 元素消失了