Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.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
Java 如何在SurfaceView上正确覆盖UI小部件?_Java_Android_Android Widget_Camera - Fatal编程技术网

Java 如何在SurfaceView上正确覆盖UI小部件?

Java 如何在SurfaceView上正确覆盖UI小部件?,java,android,android-widget,camera,Java,Android,Android Widget,Camera,我有一个肖像相机预览工作在一个相对论窗口,一个按钮和一个文本视图。它们在那里,但不可见,它们对触摸动作的反应正常。如何设置Z顺序或优先级? 这是我的main.xml: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android

我有一个肖像相机预览工作在一个相对论窗口,一个按钮和一个文本视图。它们在那里,但不可见,它们对触摸动作的反应正常。如何设置Z顺序或优先级? 这是我的main.xml:

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

<SurfaceView android:id="@+id/surface" android:layout_width="fill_parent" android:layout_height="fill_parent"></SurfaceView>
<Button android:layout_height="wrap_content" android:layout_width="match_parent" android:onClick="hablar" android:text="Button" android:id="@+id/button1"></Button>
<EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:text="EditText" android:id="@+id/edita"></EditText>
</RelativeLayout>
</FrameLayout>


ApiDemos中的SurfaceView覆盖示例演示了如何执行此操作。在这里查找“SurfaceView覆盖”部分:

嗯,我让它在框架布局中工作,其中SurfaceView与ZoomControl同级。也就是说,这个结构适合我:

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

    <SurfaceView
        android:id="@+id/surface"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <ZoomControls
        android:id="@+id/zoom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        />
</FrameLayout>


也许是相对论打破了它?

答案一点也不直观,但我发现了如何做到这一点。 与线性布局不同,声明顺序不定义相对布局中的Z顺序。 通过声明两个视图,我可以将textview覆盖在相机预览上 在XML和中,并以编程方式将它们覆盖在我的Activity的onCreate方法上

假设您有一个XML,其中包含一个文本视图,该文本视图具有一个漂亮的透明背景,您希望覆盖在相机预览帧布局上,因为为什么不呢?它看起来很酷

<RelativeLayout>
      <TextView
        android:id="@+id/txtnombotiga"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Ola ke ase"
        android:textColor="#000000"
        android:textSize="16sp"    
        android:background="#55ffffff" 
       />
  <FrameLayout
      android:id="@+id/cameraPreview"
      android:layout_width="match_parent"
      android:layout_height="240dp">     
  </FrameLayout>
</RelativeLayout>
这是一般的方法,如果你需要更多的细节让我知道。
我需要在工作中赶上最后期限,所以我使用我想到的第一个解决方案,有时不是最优雅或最有效的,如果你知道更好的方法,请与我们分享

只需在SurfaceView上放置一个视图:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">

    <SurfaceView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <View
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="lalalalala" />
</FrameLayout>


我看过这个例子,但我使用的是SurfaceView,它不起作用。有没有办法做到这一点?@hackbod我可以在小部件中使用SurfaceView吗(我已经读到它无法实现,因为它不受支持)你也可以看看这个问题吗?我面临着同样的问题,我在过去的两天里一直在这个问题上,你找到解决方法了吗?下面的URL提供了一些很好的信息:如果你在RelativeLayout中更改TextView和FrameLayout的顺序,文本将位于相机顶部。你的解决方案就是工作。天哪,你的解决方案成功了,谢谢。
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">

    <SurfaceView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <View
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="lalalalala" />
</FrameLayout>