Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.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 XML)_Android_Xml_Android Layout_Android Xml - Fatal编程技术网

在视图中的元素之间展开视图(Android XML)

在视图中的元素之间展开视图(Android XML),android,xml,android-layout,android-xml,Android,Xml,Android Layout,Android Xml,我想膨胀一些视图,但在视图底部有一个按钮。我已经知道如何动态充气视图,然后在其他充气视图下方充气按钮。但是,当只有几个膨胀视图时(导致组合视图占用的空间小于整个屏幕),按钮不会像我所希望的那样位于页面底部。我的想法是,我需要通过将按钮设置为:android:layout\u alignParentBottom,使按钮在相对布局的底部对齐(尽管应用程序崩溃,但我尝试这样做时) 这是我拥有的屏幕截图,然后是我想要的屏幕截图,你看到的所有项目都被放大到一个相对布局内的滚动视图上。我认为问题在于按钮被充

我想膨胀一些视图,但在视图底部有一个按钮。我已经知道如何动态充气视图,然后在其他充气视图下方充气按钮。但是,当只有几个膨胀视图时(导致组合视图占用的空间小于整个屏幕),按钮不会像我所希望的那样位于页面底部。我的想法是,我需要通过将按钮设置为:android:layout\u alignParentBottom,使按钮在相对布局的底部对齐(尽管应用程序崩溃,但我尝试这样做时)

这是我拥有的屏幕截图,然后是我想要的屏幕截图,你看到的所有项目都被放大到一个相对布局内的滚动视图上。我认为问题在于按钮被充气到滚动视图上,而滚动视图的大小仅与项目强制的大小相同(不幸的是,我太笨了,不知道如何充气到视图的不同部分)

左侧图像的代码如下所示(左侧视图中没有和错误): 父视图:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/blurybg"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">    
<ScrollView     
  android:layout_height="wrap_content" 
  android:id="@+id/scrollView1" 
  android:layout_width="fill_parent" >
<LinearLayout     
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id= "@+id/parent_of_inflated_view_id">
</LinearLayout>   
</ScrollView>
</RelativeLayout>
谢谢你的帮助,
亚当请检查我的密码。它应按预期工作:

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

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

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

    <Button
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

请注意,我对ScrollView使用了
android:fillViewport=“true”
,因此它可以填充整个屏幕。此外,我还使用了
android:layout\u weight
来正确拉伸视图(您可以找到属性的解释)。

请检查我的代码。它应按预期工作:

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

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

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

    <Button
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

请注意,我对ScrollView使用了
android:fillViewport=“true”
,因此它可以填充整个屏幕。此外,我还使用了
android:layout\u weight
来正确地拉伸视图(您可以找到属性的解释)。

一段代码将有助于指出您的错误。此外,还不清楚“android:layout\u alignParentBottom”失败的原因。请提供一些异常日志。仅供参考:当我尝试对齐父底部时,我没有膨胀按钮,我只是将按钮放在父视图xml中,并将其设置为对齐相对布局的父底部。我想我不能在按钮和视图顶部之间膨胀我的其他视图?一段代码将有助于指出您的错误。此外,还不清楚“android:layout\u alignParentBottom”失败的原因。请提供一些异常日志。仅供参考:当我尝试对齐父底部时,我没有膨胀按钮,我只是将按钮放在父视图xml中,并将其设置为对齐相对布局的父底部。我想我不能在按钮和视图顶部之间膨胀我的其他视图?好吧,我使用了你的代码(我实际上最初使用了类似的东西,在scrollview和我膨胀按钮的relLayout之间有一个lin布局)。这两种解决方案的问题是,在我添加了大量膨胀的视图之后,“完成”按钮总是在页面上。有没有一种方法可以让我在浏览所有膨胀的视图之前不会看到“完成”按钮?我非常感谢您的评论,我觉得这非常接近正确答案,但同时您希望按钮像第二张截图一样位于屏幕的末尾?让我想想。为什么在另一个这样的线性布局中有一个线性布局?第一个线性布局用于正确放置按钮:按钮将位于屏幕底部,当有太多膨胀元素时,它将位于它们下面(您应该滚动查看)。我认为用一种布局很难达到同样的效果。此外,这种结构看起来更符合逻辑:为膨胀的项目单独布局,这些项目与控制元素(按钮)没有任何共同之处。首先,我使用android:fillViewport=“true”使ScrollView与其父项匹配。我不知道为什么,但是android:layout\u height=“match\u parent”在ScrollView中并没有像预期的那样工作。可能是因为该视图的实际长度不同。其次,我使用android:layout\u-weight为id/layout\u的子视图设置比例,以便进行定位。尝试更改一些值,看看会发生什么。好的,我使用了你的代码(我最初使用了类似的东西,在scrollview和我将按钮放大的relLayout之间有一个lin布局)。这两种解决方案的问题是,在我添加了大量膨胀的视图之后,“完成”按钮总是在页面上。有没有一种方法可以让我在浏览所有膨胀的视图之前不会看到“完成”按钮?我非常感谢您的评论,我觉得这非常接近正确答案,但同时您希望按钮像第二张截图一样位于屏幕的末尾?让我想想。为什么在另一个这样的线性布局中有一个线性布局?第一个线性布局用于正确放置按钮:按钮将位于屏幕底部,当有太多膨胀元素时,它将位于它们下面(您应该滚动查看)。我认为用一种布局很难达到同样的效果。此外,这种结构看起来更符合逻辑:为膨胀的项目单独布局,这些项目与控制元素(按钮)没有任何共同之处。首先,我使用android:fillViewport=“true”使ScrollView与其父项匹配。我不知道为什么,但是android:layout\u height=“match\u parent”在ScrollView中并没有像预期的那样工作。可能是因为该视图的实际长度不同。其次,我使用android:layout\u-weight为id/layout\u的子视图设置比例,以便进行定位。尝试更改一些值,看看会发生什么。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

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

    <Button
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_alignParentBottom="true" />

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

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

        <LinearLayout
            android:id="@+id/parent_of_inflated_view_id"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" />

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_weight="0" />
    </LinearLayout>

</ScrollView>