gpt4 book ai didi

java - Android 窗口没有给我全屏

转载 作者:太空狗 更新时间:2023-10-29 15:09:53 25 4
gpt4 key购买 nike

我有一个问题,我要向一个 Activity 添加三个 ImageView,一个是页眉,另一个是页脚,第三个位于 ScrollView 之间。我正在使用 android_2.1_r1 版本,我注意到一个非常奇怪的问题,无法弄清楚发生了什么,尽管我可以说出它发生的原因。

似乎如果我得到 DecorView 并要求可见矩形,屏幕顶部是 x=0 y=38?它为什么要这样做。如果我将顶部图像的大小更改为大于 40,它会消失吗?

以防万一有人想到它,它不是下面的。我有这套。

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN)

见附件截图。红色条应与顶部齐平。但出于某种原因,DecorView 决定在顶部有一个插图??????任何帮助表示赞赏。

更新 1

所以我发现了问题,它是 ScrollView.setFocusableInTouchMode,请参阅下面的代码。当注释掉的行未被注释时,它会导致问题。但前提是顶部 ImageView 的高度小于 20。有人可以阐明一下吗?????我试过了。

  • 相对布局
  • 绝对布局
  • 线性布局

更新 2

仍然是陌生人,当我旋转,然后旋转回来时,它是固定的!!! x=0, y=38 的插图不见了????我屏幕顶部的黑线变成了???

更新 3

当我显示软键盘时,这个问题就消失了,就好像它重置了什么一样。我还可以通过使用反射将 Root View 插入设置为 0,使用 OnGlobalLayoutListener 修复它。

   public void onGlobalLayout() {
AndroidActivity activity = screen.getActivity();
Window window = activity.getWindow();
View view = window.getDecorView();

view.getWindowVisibleDisplayFrame(currentlyVisibleRect);

if(currentlyVisibleRect.top > 0) {
// Below code will not work....but you get the idea
Field field1 = view.getClass().getDeclaredField("mAttachInfo");
Field field2 = field.get(view).getClass().getDeclaredField("mVisibleInsets");
Rect rect = field2.get(field1.get(view));

rect.top = 0;
}
}

我宁愿没有人建议 XML 布局,我的应用程序必须非常动态并且响应关于如何创建布局的各种规则。

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsoluteLayout;
import android.widget.ScrollView;

public class AndroidLayoutManager {

private final Activity activity;
private final Rectangle bounds;
private final String name;

public AndroidLayoutManager(Activity activity, Rectangle bounds, String name) {
this.activity = activity;
this.bounds = bounds;
this.name = name;
}

public ViewGroup createLayout(ViewLayout viewLayout, ViewComponent headerView, ViewComponent mainView, ViewComponent footerView) {
AbsoluteLayout relativeLayout = new AbsoluteLayout(activity);
AbsoluteLayout.LayoutParams fullScreenParams = new AbsoluteLayout.LayoutParams(bounds.width, bounds.height, 0, 0);

if(viewLayout.isHeaderIncluded()) {
AbsoluteLayout.LayoutParams headerViewParams = headerView.getLayoutParams();
View view = headerView.getView();

view.setLayoutParams(headerViewParams);
relativeLayout.addView(view, headerViewParams);
}
if(viewLayout.isMainIncluded()) {
AbsoluteLayout.LayoutParams mainViewParams = mainView.getLayoutParams();
View view = mainView.getView();
View scrollView = createScrollView(view);

scrollView.setLayoutParams(mainViewParams);
relativeLayout.addView(scrollView, mainViewParams);
}
if(viewLayout.isFooterIncluded()) {
AbsoluteLayout.LayoutParams footerViewParams = footerView.getLayoutParams();
View view = footerView.getView();

view.setLayoutParams(footerViewParams);
relativeLayout.addView(view, footerViewParams);
}
relativeLayout.requestLayout();
activity.setContentView(relativeLayout, fullScreenParams);
mainView.getView().requestFocus();
activity.getWindow().getDecorView().requestLayout();

return relativeLayout;
}

private View createScrollView(View view) {
ScrollView scrollView = new ScrollView(activity);

// ******** WTF??? This is causing a strange layout problem *******
//scrollView.setFocusableInTouchMode(true);
scrollView.requestFocus();
scrollView.setFocusable(true);
scrollView.setVerticalScrollBarEnabled(false);
scrollView.addView(view);
scrollView.setFillViewport(true);

return scrollView;
}

@Override
public String toString() {
return name;
}

public static class ViewLayout {

private Rectangle header;
private Rectangle main;
private Rectangle footer;

public ViewLayout(Rectangle header, Rectangle main, Rectangle footer) {
this.header = header;
this.main = main;
this.footer = footer;
}

public boolean isMainIncluded() {
return main != null;
}

public boolean isFooterIncluded() {
return footer != null;
}

public boolean isHeaderIncluded() {
return header != null;
}

public Point getHeaderPoint() {
return new Point(0, 0);
}

public Point getMainPoint() {
if(header != null) {
return new Point(0, header.height);
}
return new Point(0, 0);
}

public Point getFooterPoint() {
if(header == null) {
return new Point(0, main.height);
}
return new Point(0, main.height + header.height);
}

public int getHeight() {
int totalHeight = main.height;

if(header != null) {
totalHeight += header.height;
}
if(footer != null) {
totalHeight += footer.height;
}
return totalHeight;
}
}

public static class ViewComponent {

private final Rectangle rectangle;
private final Point origin;
private final View view;

public ViewComponent(View view, Rectangle rectangle, Point origin) {
this.view = view;
this.rectangle = rectangle;
this.origin = origin;
}

public AbsoluteLayout.LayoutParams getLayoutParams() {
return new AbsoluteLayout.LayoutParams(rectangle.width, rectangle.height, origin.x, origin.y);
}

public View getView() {
return view;
}
}
}

enter image description here

最佳答案

您的代码 requestWindowFeature(...)getWindow().setFlag(....) 必须在 setContentView() 之前。这是我的通知

关于java - Android 窗口没有给我全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17763132/

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