Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.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 - Fatal编程技术网

Android 滚动背景图像和浮动按钮

Android 滚动背景图像和浮动按钮,android,Android,我需要一个屏幕,是充满了一个图像作为背景和三个按钮浮动在图像。我用xml创建了这个很好的文档,在垂直方向上,它做了我想要的事情。然而,在景观中,它不是这样的,所以我尝试添加一个滚动视图,对于如何正确组合这些元素,我感到非常困惑。经过多次尝试,我达到了如下所示的阶段 <?xml version="1.0" encoding="utf-8"?> <ScrollView android:layout_height="fill_parent" android:layout_width=

我需要一个屏幕,是充满了一个图像作为背景和三个按钮浮动在图像。我用xml创建了这个很好的文档,在垂直方向上,它做了我想要的事情。然而,在景观中,它不是这样的,所以我尝试添加一个滚动视图,对于如何正确组合这些元素,我感到非常困惑。经过多次尝试,我达到了如下所示的阶段

<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_height="fill_parent"
android:layout_width="fill_parent" android:id="@+id/home_container"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:src="@drawable/alert"
    android:layout_height="fill_parent" android:layout_width="fill_parent"
    android:scaleType="fitCenter" android:clickable="true"
    android:enabled="true" />
<LinearLayout android:layout_width="fill_parent"
    android:paddingBottom="25px" android:paddingLeft="25px"
    android:orientation="vertical" android:paddingTop="90px"       android:id="@+id/toplinear"
    android:layout_height="fill_parent" android:paddingRight="25px"
    android:gravity="top">
    <Button android:layout_width="fill_parent" android:textSize="20dp"
        android:id="@+id/startprogrambutton" android:paddingBottom="12dp"
        android:text="@string/text1" android:layout_height="wrap_content"
        android:paddingTop="12dp"></Button>
    <Button android:layout_width="fill_parent" android:textSize="20dp"
        android:id="@+id/button1" android:paddingBottom="12dp"
        android:layout_marginTop="10dp" android:background="@drawable/webview_buttons"
        android:text="@string/text2" android:layout_height="wrap_content"
        android:paddingTop="12dp"></Button>
    <Button android:layout_width="fill_parent" android:textSize="20dp"
        android:id="@+id/button2" android:paddingBottom="12dp"
        android:layout_marginTop="10dp" android:background="@drawable/webview_buttons"
        android:text="@string/text3" android:layout_height="wrap_content"
        android:paddingTop="12dp"></Button>
    <Button android:layout_width="fill_parent" android:textSize="20dp"
        android:id="@+id/button3" android:paddingBottom="12dp"
        android:layout_marginTop="10dp" android:background="@drawable/webview_buttons"
        android:text="@string/text4" android:layout_height="wrap_content"
        android:paddingTop="12dp"></Button>
</LinearLayout>
现在,scrollview中的it错误只能包含一个子项。有没有什么方法可以重新排列,使我的图像和浮动按钮一起滚动?

将ImageView和LinearLayout放在另一个垂直LinearLayout中。这解决了scrollView子问题

<ScrollView>
<LinearLayout>
<Imageview />
<LinearLayout />
</LinearLayout>
</ScrollView>

你为什么不把图像作为背景,用按钮进行线性布局呢?这样可以达到你的目的

如果您只想滚动按钮而不想滚动图像视图,可以尝试以下操作:

<LinearLayout>
    <Imageview />
    <ScrollView>
        <LinearLayout>
            <Button />
            <Button />
            <Button />
            <Button />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

希望这有帮助

正如您所知,您不局限于为两个方向寻找单一解决方案。通过在land&port目录中指定单独的布局xml文件,两个方向可以有两个单独的布局。请参见此处的官方文档:


这就停止了出错,但现在图像不是背景,而是按钮上方的一个单独元素。我忘了提到,当它作为非滚动工作正常时,我的所有内容都在一个框架布局中。据我所知,scrollview是一种框架布局,我以为它会取代它。使用android:background=@drawable/alert属性作为带按钮的线性布局。移除imageView,是的,您也可以将其替换为frameLayout。将框架布局放在scrollview中。谢谢Yashwanth-背景属性。谢谢您的帮助