我遇到了一个不调用其自身的横向布局的片段的问题。当你旋转设备,它将恢复到以前的片段,并把该进的logcat:当设备旋转时,片段没有加载横向布局,回复到之前的片段
细目:
我在片段A,按下一个按钮和我带到片段B.当我旋转设备,片段A以横向视图显示。
requestLayout()被android.widget.ListView错误地调用{43a67d00 VFED.VC. ...... ID 0,0-720,1845}布局过程:在运行的第二布局传递
E/ViewRootImpl:sendUserActionEvent()MVIEW == NULL
如果该设备已经被旋转然后选择片段,横向布局加载得很好,就在您处于片段本身中时。
这里是片段的代码,我希望你能帮助!
public class nandos_Fragment extends Fragment implements View.OnClickListener {
View rootview;
MapView mMapView;
private GoogleMap googleMap;
public static Button scanBtn;
public static int retrievedResult = 0;
private static final String TAG = "MyActivity";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootview = inflater.inflate(R.layout.nandos_layout, container, false);
scanBtn = (Button) rootview.findViewById(R.id.scan_button);
scanBtn.setOnClickListener(this);
mMapView = (MapView) rootview.findViewById(R.id.mapView);
mMapView.onCreate(savedInstanceState);
mMapView.onResume();// needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
googleMap = mMapView.getMap();
// latitude and longitude
double latitude = 52.955491;
double longitude = -1.149885;
// create marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latitude, longitude)).title("Nandos Nottingham!");
// Changing marker icon
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
// adding marker
googleMap.addMarker(marker);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(52.955491, -1.149885)).zoom(15).build();
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
return rootview;
}
public void onClick(View v) {
//respond to clicks
if (v.getId() == R.id.scan_button) {
//scan
if (retrievedResult == 0) {
IntentIntegrator scanIntegrator = new IntentIntegrator(getActivity());
scanIntegrator.initiateScan();
}else{}
}
}
@Override
public void onResume() {
super.onResume();
mMapView.onResume();
Random r = new Random();
int i1 = r.nextInt(80 - 65) + 65;
if (result != null) {
scanBtn.setText("Code: " + result + i1);
retrievedResult = 1;
}
}
@Override
public void onPause() {
super.onPause();
mMapView.onPause();
scanBtn.setText("Get Offer!");
retrievedResult = 0;
result = null;
}
@Override
public void onDestroy() {
Log.v(TAG, "ON DESTROY");
mMapView.onDestroy();
super.onDestroy();
}
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.user.ntuio" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="com.ram.googlemapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ntsu"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme" >
<activity
android:name=".HomeActivity"
android:label="@string/title_activity_nav_bar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="****"/>
</application>
</manifest>
你可以发布你的Manifest文件。 – 2015-03-08 20:52:38
另外,看看这个帖子:http://stackoverflow.com/questions/18533693/app-shows-main-screen-after-screen-rotation – 2015-03-08 20:54:49
@DanielNugent感谢您的答复,我应该保存状态特别是?什么导致这个错误发生? – 2015-03-08 21:28:16