我需要移動屏幕左側的內容之外的版面內容,這樣我就可以使房間的滑動菜單右側 如何移動屏幕的Android
下面是代碼:
// modify content layout params
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);
}
FrameLayout.LayoutParams pr = (android.widget.FrameLayout.LayoutParams) content
.getLayoutParams();
pr.rightMargin = menuSize;
content.setLayoutParams(pr);
// add the slide menu to parent
parent = (FrameLayout) content.getParent();
try {
parent = (FrameLayout) content.getParent();
} catch (ClassCastException e) {
/*
* Most probably a LinearLayout, at least on Galaxy S3.
*/
LinearLayout realParent = (LinearLayout) content.getParent();
parent = new FrameLayout(act);
realParent.addView(parent, 0); // add FrameLayout to real parent of
// content
realParent.removeView(content); // remove content from real parent
parent.addView(content); // add content to FrameLayout
}
LayoutInflater inflater = (LayoutInflater) act
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
menu = inflater.inflate(R.layout.slidemenu, null);
FrameLayout.LayoutParams lays = new FrameLayout.LayoutParams(menuSize,
FrameLayout.LayoutParams.MATCH_PARENT, Gravity.RIGHT);
lays.setMargins(0, statusHeight, 0, 0);
menu.setLayoutParams(lays);
parent.addView(menu);
但我得到的是: 內容只是調整大小以適應屏幕,我怎樣才能使這項工作? 順便說一句我不能修改內容佈局它的相對佈局與surfaceview,但它應該與任何佈局,因爲我修改DecorView這是頂視圖容器
我這樣做FrameLayout.LayoutParams pr =(android.widget.FrameLayout.LayoutParams)content .getLayoutParams(); pr.rightMargin = menuSize; content.setLayoutParams(pr);和菜單和動畫和所有準備就緒,我只需要這個修復 – user924941
@ user924941我更新了我的答案昨天舉了一個例子,這有助於回答你的問題嗎? – Ryan