如何随意改变视图的位置和大小视图、随意、大小、位置

2023-09-04 04:52:03 作者:╰︶ ̄天天花酒夜夜高歌。

我工作的一个 Android的广告SDK 。这 SDK 将收取取广告的资源,并在web视图进行播放。

I am working on an Android Advertisement SDK. This SDK will charge fetch Advertisement resource and play it in a WebView.

根据广告的内容 SDK 需要修改的WebView的位置和大小。例如,一个横幅广告将在顶部或屏幕的底部订货量大,有些广告可能发生在中心,向左或向右。

Depending on the content of the Advertisement, the SDK need to change the WebView's position and size. For Example, A banner advertisement will palce in the top or bottom of screen, some advertisement maybe place at center, left or right.

现在我需要的用户放置的WebView 的FrameLayout ,所以我可以改变的位置和大小的WebView 随意,不影响其他视图。我可以设置 FrameLayout.LayoutParameters 来调整位置和大小。

Now I need the users to place the WebView in FrameLayout, So I could change the position and size of WebView at will and don't affect other views. I could set FrameLayout.LayoutParameters to adjust position and size.

显然,这是一种强限制为用户。也许他们想用 RelativeLayout的等。

Obviously, this is a strong restriction for users. Maybe they want use RelativeLayout and others.

那么,有没有人有关于我的问题的想法?我想现在使用的片段,不知道将它的工作。

So is there anyone have ideas about my issue? I am trying to use fragment now and didn't know would it work.

推荐答案

我弄明白这个问题。

每一个Android应用程序是底座上的的FrameLayout(android.R.id.content)。当我需要改变视图的位置。我可以从当前布局中删除视图,并把它添加到的FrameLayout(android.R.id.content)。

Every android app is base on a FrameLayout(android.R.id.content).When I need to change position of a view. I could remove the view from its current layout and add it to FrameLayout(android.R.id.content).

这就是我想要的。