android - ScrollView 和线性布局

标签 android layout

我试图在 Android 中获得一个非常简单的布局,但我无法让它工作。我想要的只是一个标题(通过 include 一个 XML 文件),然后是一个 ScrollView 以显示大量文本,底部有两个按钮,应该始终可见。

我摆弄过 LinearLayoutRelativeLayout,但不知何故,我无法让它工作。到目前为止,我所拥有的是:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">

    <include layout="@layout/header" />


    <RelativeLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <ScrollView
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:id="@+id/svDisclaimer"
        >
           <TextView 
               android:layout_width="fill_parent"
               android:layout_height="wrap_content" 
               android:id="@+id/tvDisclaimer">
           </TextView>
    </ScrollView>
         <LinearLayout      android:orientation="horizontal" 
              android:layout_width="fill_parent" 
              android:layout_height="wrap_content" 
              android:layout_below="@+id/svDisclaimer"
               >
      .. [ snip ] ..
        </LinearLayout>
        </RelativeLayout>
</LinearLayout>

( .. [snip] .. 是我的按钮所在的位置) 标题在那里, ScrollView 弹出,但按钮无处可见。

最佳答案

您的 ScrollView 的高度设置为 fill_parent,这会将 ScrollView 下面的所有内容推离屏幕底部。您将永远看不到无法滚动到的内容...请尝试使用此模式:

<ScrollView >
    <RelativeLayout >
        <TextView />
        <LinearLayout >
            <!-- [ snip ] -->
        </LinearLayout>
    </RelativeLayout>
</ScrollView>

您也可以使用 RelativeLayout 位置标签删除 LinearLayout。 (android:belowandroid:toRightOf 等)


尝试使用我评论中的这个配置:

<ScrollView
    ...
    android:above="@+id/buttons" >

    ...
</ScrollView>
<LinearLayout
    android:id="@+id/buttons"
    android:layout_alignParentBottom="true"
    ... >

    ...
</LinearLayout>

关于android - ScrollView 和线性布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12789532/

相关文章:

android - fragment Activity 中的空指针异常

iphone - 关于在 iOS 和 Android 上开发多人游戏的建议?

android - 错误 : <item> tag requires a 'drawable' attribute or child tag defining a drawable

ruby-on-rails - 如何将 RoR View 转换为响应式 (html5)

css - 哪种测量单位最适合网页布局,px、百分比或 em?

css - 带有 CSS 问题的简单图库在 block 中显示

java - JSON POST 请求使用 Php 从 Android 中的 HttpClient 从服务器端接收?

java - libgdx opengl 错误

android - 当我尝试在 Facebook (FQL) 中使用它时,我的应用程序的访问 token 不起作用

java - 使用GridBagLayout在一个面板中设置多个组件,但我不想填满整个面板