如何安装Android Z命令?

Mic*_*ico 4 android android-layout android-framelayout

在我的应用程序中,我想在背景图像上绘制.我有以下xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg2"
>
    <com.myapp.drawings.DrawingSurface
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/drawingSurface"
    />
    <LinearLayout
            android:orientation="horizontal"
            android:background="@drawable/bg2" 
            android:layout_width="match_parent" 
            android:layout_height="match_parent">
        <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="OK"
                android:onClick="onClick"
                android:id="@+id/colorBlueBtn"
        />
        <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Save"
                android:onClick="onClick"
                android:id="@+id/saveBtn"
        />
    </LinearLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

不,问题是,当我尝试在绘图表面上绘图时,我的绘图没有显示.显示了背景图像和按钮.一旦我保存它,我的应用程序生成的图像文件就会显示出来.我认为问题是我的布局的Z顺序.

有任何想法吗?谢谢你的帮助!:)

Dmi*_*nko 8

首先会先绘制以xml格式显示的项目.所以你的表面视图在你的线性布局之下.


Adi*_*nia 5

根据Android开发者对FrameLayout的描述

子视图以堆栈形式绘制,最近添加的子项位于顶部.

因此,在您的xml中,LinearLayout绘制最后一个,并且因为它具有match_parent属性,所以它完全隐藏了绘图表面.

所以,尝试使用a RelativeLayout,并将LinearLayout属性设置为just wrap_content,类似于:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg2"
>
    <com.myapp.drawings.DrawingSurface
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/drawingSurface"
    />
    <LinearLayout
            android:orientation="horizontal"
            android:background="@drawable/bg2" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true">
        <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="OK"
                android:onClick="onClick"
                android:id="@+id/colorBlueBtn"
        />
        <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Save"
                android:onClick="onClick"
                android:id="@+id/saveBtn"
        />
    </LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

你也可以完全省略LinearLayout,只需设置按钮属性以保持在底部等.