0

我需要在左侧移动屏幕内容,因此我使用此代码来获取内容

try {
        content = ((LinearLayout) act.findViewById(android.R.id.content)
                .getParent());
    } catch (ClassCastException e) {
        /*
         * When there is no title bar
         * (android:theme="@android:style/Theme.NoTitleBar"), the
         * android.R.id.content FrameLayout is directly attached to the
         * DecorView, without the intermediate LinearLayout that holds the
         * titlebar plus content.
         */
        content = (FrameLayout) act.findViewById(android.R.id.content);
    }

我注意到在 android > 3.0 的设备上,内容设置在 try 块中,在设备 < 3.0 上,它进入 catch 块。这里我移动内容:

FrameLayout.LayoutParams pr = (android.widget.FrameLayout.LayoutParams) content
                    .getLayoutParams();
            pr.rightMargin = menuSize;
            pr.leftMargin = -menuSize;
            content.setLayoutParams(pr);

因此,在设备 >3.0 上一切正常,内容 si 移动,在设备 <3.0 上什么都没有发生,内容只是坐着没有变化

4

1 回答 1

0

如果未设置重力,则找到答案 FrameLayout 不会考虑边距。

于 2013-01-23T17:37:46.913 回答