gpt4 book ai didi

android - 如何将自定义 View 置于 Android 内置 View 之上?

转载 作者:行者123 更新时间:2023-11-30 04:53:03 25 4
gpt4 key购买 nike

我正在为 Android 开发一个小应用程序。我正在创建自己的 View 。

我计划将布局设计为:

<LinearLayout>
<MyView>
<Button><Button>
</LinearLayout>

但是当我运行我的程序时,我的自定义 View 将覆盖整个屏幕。有什么办法可以避免这种情况吗?

我已经试过将android:layout_width, layout_height 加成wrap_content, fill_partent, 但是不行运气。

最佳答案

我通常在我想要自定义 View 的地方放置一个 FrameLayout,然后是我创建 View 并将其添加到 FrameLayout 的代码。

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0BF">

<FrameLayout
android:id="@+id/GLFrame"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/ActivityFrame"
android:layout_height="fill_parent"
android:layout_width="fill_parent" />

</FrameLayout>

以及通过这样的代码进行访问。

FrameLayout glFrame = (FrameLayout)findViewById(R.id.GLFrame);
glFrame.addView(new NativeBackgroundSurface(this));

关于android - 如何将自定义 View 置于 Android 内置 View 之上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2426456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com