tôi cần phải di chuyển nội dung của màn hình sang bên trái, vì vậy tôi có thể nhường chỗ cho menu trượt bên phải Làm thế nào để di chuyển một nội dung bố trí bên ngoài màn hình android
Đây là mã:
// 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);
nhưng những gì tôi nhận được là: nội dung chỉ được thay đổi kích cỡ để phù hợp với màn hình, làm thế nào tôi có thể làm công việc này? Btw tôi không thể sửa đổi bố cục nội dung bố cục tương đối của nó bằng surfaceview, nhưng nó sẽ hoạt động với bất kỳ bố cục nào bởi vì tôi sửa đổi DecorView đó là khung nhìn trên cùng của trang
tôi làm điều này ở đây FrameLayout.LayoutParams pr = (android.widget.FrameLayout.LayoutParams) content .getLayoutParams(); pr.rightMargin = menuSize; content.setLayoutParams (pr); và menu và hình động và tất cả đều sẵn sàng tôi chỉ cần sửa lỗi này – user924941
@ user924941 Tôi cập nhật câu trả lời của mình hôm qua với một ví dụ, điều này có giúp trả lời câu hỏi của bạn không? – Ryan