安卓布局:在父级上看不到子项



我有你在图片中看到的布局(对不起,我还不能正常发布它们):https://dl.dropboxusercontent.com/u/28640502/Unbenannt.bmp

但是,当我执行应用程序时,我只能看到相机预览,而看不到文本或 SeekBar。我知道它们有效,因为当我减小相机的尺寸时,我可以看到它们并进行交互,但如果我希望相机像背景一样,然后是孩子们,那就行不通了。

我一直在检查很多有类似问题的线程,但我没有找到解决方案:1, 2, 3...知道吗?多谢!

这是我的 xml 代码以防万一:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.55"
    android:orientation="vertical" >
    <FrameLayout
        android:id="@+id/camera_preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
            <TextView
                android:id="@+id/show_height"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5sp"
                android:layout_marginRight="10sp"
                android:layout_weight="0.12"
                android:text="H" />
            <SeekBar
                android:id="@+id/select_height"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_margin="5sp"
                android:layout_weight="0.91" />
            <TextView
                android:id="@+id/show_distance"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.06"
                android:text="Dist" />
        </LinearLayout>
    </FrameLayout>
</LinearLayout>
例如尝试

在相对布局中输入两个布局

<LL>
  <RL>
    <FL>
    </FL>
    <LL>
    </LL>
  </RL>
</LL>

这是由于FL对LL的过度困扰而造成的

您可以使用 View 类的 bringToFront() 方法。

SeekBar seeker = (SeekBar)findViewById(R.id.select_height);
seeker.bringToFront();

通常,您可以使用 sendToBack() 函数将视图放在其他视图后面。

另请记住,视图的 z 索引由视图在 xml 布局文件中声明的顺序确定。

我还建议更改相机预览布局,这是第一个子布局是兄弟姐妹。在 xml 文件中最后添加的那个将位于顶部。

最新更新