Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 带滚动中心的三组件用户界面_Android_Xml - Fatal编程技术网

Android 带滚动中心的三组件用户界面

Android 带滚动中心的三组件用户界面,android,xml,Android,Xml,我目前正在做一个android项目,我想把屏幕分成三个部分 第一部分将是一个标题,它不会在屏幕顶部移动。 第二部分是可滚动的主要内容 第三部分是固定在屏幕底部的两个按钮 在这种设置中,顶部和底部将保持在屏幕上,只有屏幕的中心部分可以滚动 出于某种原因,当我尝试这样做时,顶部和中间的工作很好,但底部有按钮却从未显示出来 下面是我用来让它工作的代码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andr

我目前正在做一个android项目,我想把屏幕分成三个部分

第一部分将是一个标题,它不会在屏幕顶部移动。 第二部分是可滚动的主要内容 第三部分是固定在屏幕底部的两个按钮

在这种设置中,顶部和底部将保持在屏幕上,只有屏幕的中心部分可以滚动

出于某种原因,当我尝试这样做时,顶部和中间的工作很好,但底部有按钮却从未显示出来

下面是我用来让它工作的代码

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/start_eulaTitle"
            android:textSize="15dp"
            android:textStyle="bold" />
        <ScrollView 
            android:layout_width="fill_parent"
            android:layout_height="match_parent">
            <TextView 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/start_eula" />
        </ScrollView>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
        <Button android:id="@+id/start_btnAgree"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/button_agree" />
        </LinearLayout>
    </LinearLayout>


谢谢你能提供的帮助

相对论也许是实现你想要的目标的途径。比如:

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

    <TextView
        android:id="@+id/title_textview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/start_eulaTitle"
        android:textSize="15dp"
        android:textStyle="bold" />

    <ScrollView
        android:id="scrolling_layout"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/button_layout"
        android:layout_below="@+id/title_textview" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/start_eula" />
    </ScrollView>

    <LinearLayout
        android:id="@+id/button_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/start_btnAgree"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/button_agree" />

        <Button
            android:id="@+id/start_btnAgree"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/button_agree" />
    </LinearLayout>

</RelativeLayout>

这基本上告诉带有按钮的线性布局始终与屏幕底部对齐,而标题文本视图默认位于左上方。可滚动区域定义为介于这两个区域之间:标题下方但按钮上方

//编辑:如果您真的想使用LinearLayout作为根,您还可以执行以下操作:

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

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/start_eulaTitle"
        android:textSize="15dp"
        android:textStyle="bold" />

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="0dp" 
        android:layout_weight="1">

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/start_eula" />
    </ScrollView>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/start_btnAgree"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/button_agree" 
            android:layout_weight="1"/>

        <Button
            android:id="@+id/start_btnAgree"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/button_agree"
            android:layout_weight="1" />
    </LinearLayout>

</LinearLayout>


通过将ScrollView的权重设置为
1
,可以实现神奇的效果。这将尽可能动态地拉伸视图,而不会将任何内容推离屏幕。

问题是您已经为中间和底部元素定义了
android:layout\u height=“match\u parent”
(分别为
“fill\u parent”
,两者相同)。从上到下布局时,所有可用空间都将提供给滚动视图。 您应该查看一下
android:layout\u weight
参数,或者您可以设置一个特定的
layout\u height
,例如15dp或诸如此类,尽管这些绝对值在android上不是很好(由于所有这些屏幕大小和分辨率不同)