내 앱에서 onConfigurationChanged
을 구현합니다. 여기에서 버튼을 사용하여 위치를 변경하고 imageView
을 새로운 구성과 일치시킵니다.레이아웃 매개 변수가 변경된 후 레이아웃 기능이 작동하지 않습니다.
가로 모드로 변경하면 버튼이 작동하지 않습니다. 즉, onClickListener
이 작동하지 않습니다.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
System.out.println("changed!");
if (PackageBuilder.popupW!=null)
if (PackageBuilder.popupW.isShowing()) {
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
RelativeLayout.LayoutParams imageviewp = (RelativeLayout.LayoutParams) (PackageBuilder.popUpView.findViewById(R.id.mImageView)).getLayoutParams();
imageviewp.topMargin=(int)((screenHeight)/(4.15));
imageviewp.height=(int)((screenHeight)*(0.25)); //250
imageviewp.width=(int)((screenWidth)*(0.3125)); //200
RelativeLayout.LayoutParams a=(RelativeLayout.LayoutParams) (PackageBuilder.popUpView.findViewById(R.id.imageViewR)).getLayoutParams();
a.height=(int)((screenHeight)*(0.25));
a.width=(int)((screenWidth)*(0.3125));
}
else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
RelativeLayout.LayoutParams imageviewp = (RelativeLayout.LayoutParams) (PackageBuilder.popUpView.findViewById(R.id.mImageView)).getLayoutParams();
imageviewp.topMargin=(int)((screenHeight)/(2));
imageviewp.height=((int) ((screenHeight)*(0.15))); //120
imageviewp.width=((int) ((screenWidth)*(0.145))); //70
RelativeLayout.LayoutParams a=(RelativeLayout.LayoutParams) (PackageBuilder.popUpView.findViewById(R.id.imageViewR)).getLayoutParams();
a.height=((int) ((screenHeight)*(0.15)));
a.width=((int) ((screenWidth)*(0.145)));
}
}
}
콘텐츠 뷰를 변경하지 않고 있으며, 레이아웃 위젯에 대한 참조를 받고 레이아웃 매개 변수를 변경하기 만합니다.
메니 페스트에서 android : configChanges = "keyboardHidden | orientation | screenSize"를 사용해야합니까? 이 작업을 수행하려면 onConfigurationChanged를 구현해야합니까? – user2162550
아니요, android : configChanges 및 neather implement onConfigurationChanged를 사용하면 안됩니다. 두 가지를 모두 꺼내서 새 레이아웃을 레이아웃 영역에 배치하십시오. 세로 방향에서는 레이아웃 폴더 내부의 XML이로드되고 가로 방향의 XML은 레이아웃 내부의 XML로로드됩니다. – tibuurcio