我需要你的帮助。我正在尝试从智能手机的传感器读取数据。这就是为什么我试着写一些代码。过了一会儿,我在互联网上找到了一个代码。但它不起作用我不知道为什么。在此代码中,有两个页面用于选择传感器,另一个用于获取数据。
我在这里复制代码。最后我会告诉你问题是什么。
这是MAIN活动代码。
package com.example.sensorlistactivity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class SensorListActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sensor_main);
SensorSelectorFragment sensorSelect = (SensorSelectorFragment) getSupportFragmentManager()
.findFragmentById(R.id.frag_sensor_select);
SensorDisplayFragment sensorDisplay = (SensorDisplayFragment) getSupportFragmentManager()
.findFragmentById(R.id.frag_sensor_view);
sensorSelect.setSensorDisplay(sensorDisplay);
}
}
这是SENSOR SELECTOR CODE。
package com.example.sensorlistactivity;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class SensorSelectorFragment extends ListFragment {
private static final String TAG = "SensorSelectorFragment";
private SensorDisplayFragment sensorDisplay;
public void setSensorDisplay(SensorDisplayFragment sensorDisplay) {
this.sensorDisplay = sensorDisplay;
SensorManager sensorManager = (SensorManager) getActivity()
.getSystemService(Activity.SENSOR_SERVICE);
List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
this.setListAdapter(new SensorListAdapter(getActivity()
.getApplicationContext(), android.R.layout.simple_list_item_1,
sensors));
}
private void showSensorFragment(Sensor sensor) {
sensorDisplay.displaySensor(sensor);
FragmentTransaction ft = getActivity().getSupportFragmentManager()
.beginTransaction();
ft.hide(this);
ft.show(sensorDisplay);
ft.addToBackStack("Showing sensor: " + sensor.getName());
ft.commit();
}
private class SensorListAdapter extends ArrayAdapter<Sensor> {
public SensorListAdapter(Context context, int textViewResourceId,
List<Sensor> sensors) {
super(context, textViewResourceId, sensors);
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
final Sensor selectedSensor = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(
android.R.layout.simple_list_item_1, null);
}
((TextView) convertView).setText(selectedSensor.getName());
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (BuildConfig.DEBUG) {
Log.d(TAG,
"display sensor! " + selectedSensor.getName());
}
showSensorFragment(selectedSensor);
}
});
return convertView;
}
}
}
这是DISPLAYMENT CODE。
package com.example.sensorlistactivity;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.content.Context;
import android.hardware.Sensor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
public class SensorDisplayFragment extends Fragment implements
SensorEventListener {
private static final String TAG = "SensorDisplayFragment";
private static final String THETA = "\u0398";
private static final String ACCELERATION_UNITS = "m/s\u00B2";
private SensorManager sensorManager;
private Sensor sensor;
private TextView name;
private TextView type;
private TextView maxRange;
private TextView minDelay;
private TextView power;
private TextView resolution;
private TextView vendor;
private TextView version;
private TextView accuracy;
private TextView timestampLabel;
private TextView timestamp;
private TextView timestampUnits;
private TextView dataLabel;
private TextView dataUnits;
private TextView xAxis;
private TextView xAxisLabel;
private TextView yAxis;
private TextView yAxisLabel;
private TextView zAxis;
private TextView zAxisLabel;
private TextView singleValue;
private TextView cosLabel;
private TextView cos;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.sensor_view, null);
sensorManager = (SensorManager) getActivity().getSystemService(
Context.SENSOR_SERVICE);
name = (TextView) layout.findViewById(R.id.name);
type = (TextView) layout.findViewById(R.id.type);
maxRange = (TextView) layout.findViewById(R.id.maxRange);
minDelay = (TextView) layout.findViewById(R.id.minDelay);
power = (TextView) layout.findViewById(R.id.power);
resolution = (TextView) layout.findViewById(R.id.resolution);
vendor = (TextView) layout.findViewById(R.id.vendor);
version = (TextView) layout.findViewById(R.id.version);
accuracy = (TextView) layout.findViewById(R.id.accuracy);
timestampLabel = (TextView) layout.findViewById(R.id.timestampLabel);
timestamp = (TextView) layout.findViewById(R.id.timestamp);
timestampUnits = (TextView) layout.findViewById(R.id.timestampUnits);
dataLabel = (TextView) layout.findViewById(R.id.dataLabel);
dataUnits = (TextView) layout.findViewById(R.id.dataUnits);
xAxis = (TextView) layout.findViewById(R.id.xAxis);
xAxisLabel = (TextView) layout.findViewById(R.id.xAxisLabel);
yAxis = (TextView) layout.findViewById(R.id.yAxis);
yAxisLabel = (TextView) layout.findViewById(R.id.yAxisLabel);
zAxis = (TextView) layout.findViewById(R.id.zAxis);
zAxisLabel = (TextView) layout.findViewById(R.id.zAxisLabel);
singleValue = (TextView) layout.findViewById(R.id.singleValue);
cosLabel = (TextView) layout.findViewById(R.id.cosLabel);
cos = (TextView) layout.findViewById(R.id.cos);
layout.findViewById(R.id.delayFastest).setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
sensorManager
.unregisterListener(SensorDisplayFragment.this);
sensorManager.registerListener(
SensorDisplayFragment.this, sensor,
SensorManager.SENSOR_DELAY_FASTEST);
}
});
layout.findViewById(R.id.delayGame).setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
sensorManager
.unregisterListener(SensorDisplayFragment.this);
sensorManager.registerListener(
SensorDisplayFragment.this, sensor,
SensorManager.SENSOR_DELAY_GAME);
}
});
layout.findViewById(R.id.delayNormal).setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
sensorManager
.unregisterListener(SensorDisplayFragment.this);
sensorManager.registerListener(
SensorDisplayFragment.this, sensor,
SensorManager.SENSOR_DELAY_NORMAL);
}
});
layout.findViewById(R.id.delayUi).setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
sensorManager
.unregisterListener(SensorDisplayFragment.this);
sensorManager.registerListener(
SensorDisplayFragment.this, sensor,
SensorManager.SENSOR_DELAY_UI);
}
});
return layout;
}
public void displaySensor(Sensor sensor) {
if (BuildConfig.DEBUG) {
Log.d(TAG, "display the sensor");
}
this.sensor = sensor;
name.setText(sensor.getName());
type.setText(String.valueOf(sensor.getType()));
maxRange.setText(String.valueOf(sensor.getMaximumRange()));
// minDelay.setText(String.valueOf(sensor.getMinDelay()));
power.setText(String.valueOf(sensor.getPower()));
resolution.setText(String.valueOf(sensor.getResolution()));
vendor.setText(String.valueOf(sensor.getVendor()));
version.setText(String.valueOf(sensor.getVersion()));
sensorManager.registerListener(this, sensor,
SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
switch (accuracy) {
case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
this.accuracy.setText("SENSOR_STATUS_ACCURACY_HIGH");
break;
case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
this.accuracy.setText("SENSOR_STATUS_ACCURACY_MEDIUM");
break;
case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
this.accuracy.setText("SENSOR_STATUS_ACCURACY_LOW");
break;
case SensorManager.SENSOR_STATUS_UNRELIABLE:
this.accuracy.setText("SENSOR_STATUS_UNRELIABLE");
break;
}
}
@Override
public void onSensorChanged(SensorEvent event) {
onAccuracyChanged(event.sensor, event.accuracy);
timestampLabel.setVisibility(View.VISIBLE);
timestamp.setVisibility(View.VISIBLE);
timestamp.setText(String.valueOf(event.timestamp));
timestampUnits.setVisibility(View.VISIBLE);
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
showEventData("Acceleration - gravity on axis", ACCELERATION_UNITS,
event.values[0], event.values[1], event.values[2]);
break;
case Sensor.TYPE_MAGNETIC_FIELD:
showEventData("Abient Magnetic Field", "uT", event.values[0],
event.values[1], event.values[2]);
break;
case Sensor.TYPE_GYROSCOPE:
showEventData("Angular speed around axis", "radians/sec",
event.values[0], event.values[1], event.values[2]);
break;
case Sensor.TYPE_LIGHT:
showEventData("Ambient light", "lux", event.values[0]);
break;
case Sensor.TYPE_PRESSURE:
showEventData("Atmospheric pressure", "hPa", event.values[0]);
break;
case Sensor.TYPE_PROXIMITY:
showEventData("Distance", "cm", event.values[0]);
break;
case Sensor.TYPE_GRAVITY:
showEventData("Gravity", ACCELERATION_UNITS, event.values[0],
event.values[1], event.values[2]);
break;
case Sensor.TYPE_LINEAR_ACCELERATION:
showEventData("Acceleration (not including gravity)",
ACCELERATION_UNITS, event.values[0], event.values[1],
event.values[2]);
break;
case Sensor.TYPE_ROTATION_VECTOR:
showEventData("Rotation Vector", null, event.values[0],
event.values[1], event.values[2]);
xAxisLabel.setText("x*sin(" + THETA + "/2)");
yAxisLabel.setText("y*sin(" + THETA + "/2)");
zAxisLabel.setText("z*sin(" + THETA + "/2)");
if (event.values.length == 4) {
cosLabel.setVisibility(View.VISIBLE);
cos.setVisibility(View.VISIBLE);
cos.setText(String.valueOf(event.values[3]));
}
break;
case Sensor.TYPE_ORIENTATION:
showEventData("Angle", "Degrees", event.values[0], event.values[1],
event.values[2]);
xAxisLabel.setText(R.string.azimuthLabel);
yAxisLabel.setText(R.string.pitchLabel);
zAxisLabel.setText(R.string.rollLabel);
break;
case Sensor.TYPE_RELATIVE_HUMIDITY:
showEventData("Relatice ambient air humidity", "%", event.values[0]);
break;
case Sensor.TYPE_AMBIENT_TEMPERATURE:
showEventData("Ambien temperature", "degree Celcius",
event.values[0]);
break;
}
}
private void showEventData(String label, String units, float x, float y,
float z) {
dataLabel.setVisibility(View.VISIBLE);
dataLabel.setText(label);
if (units == null) {
dataUnits.setVisibility(View.GONE);
} else {
dataUnits.setVisibility(View.VISIBLE);
dataUnits.setText("(" + units + "):");
}
singleValue.setVisibility(View.GONE);
xAxisLabel.setVisibility(View.VISIBLE);
xAxisLabel.setText(R.string.xAxisLabel);
xAxis.setVisibility(View.VISIBLE);
xAxis.setText(String.valueOf(x));
yAxisLabel.setVisibility(View.VISIBLE);
yAxisLabel.setText(R.string.yAxisLabel);
yAxis.setVisibility(View.VISIBLE);
yAxis.setText(String.valueOf(y));
zAxisLabel.setVisibility(View.VISIBLE);
zAxisLabel.setText(R.string.zAxisLabel);
zAxis.setVisibility(View.VISIBLE);
zAxis.setText(String.valueOf(z));
}
private void showEventData(String label, String units, float value) {
dataLabel.setVisibility(View.VISIBLE);
dataLabel.setText(label);
dataUnits.setVisibility(View.VISIBLE);
dataUnits.setText("(" + units + "):");
singleValue.setVisibility(View.VISIBLE);
singleValue.setText(String.valueOf(value));
xAxisLabel.setVisibility(View.GONE);
xAxis.setVisibility(View.GONE);
yAxisLabel.setVisibility(View.GONE);
yAxis.setVisibility(View.GONE);
zAxisLabel.setVisibility(View.GONE);
zAxis.setVisibility(View.GONE);
}
@Override
public void onHiddenChanged(boolean hidden) {
super.onHiddenChanged(hidden);
if (hidden) {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Unregistering listener");
}
sensorManager.unregisterListener(this);
}
}
@Override
public void onPause() {
super.onPause();
if (BuildConfig.DEBUG) {
Log.d(TAG, "onPause");
Log.d(TAG, "Unregistering listener");
}
sensorManager.unregisterListener(this);
}
}
问题是:当我运行此代码时,存在nullPointerExpection。 在主要活动中,“sensorSelect”和“sensorDisplay”为空。换句话说,这部分不起作用。
SensorSelectorFragment sensorSelect = (SensorSelectorFragment) getSupportFragmentManager()
.findFragmentById(R.id.frag_sensor_select);
SensorDisplayFragment sensorDisplay = (SensorDisplayFragment) getSupportFragmentManager()
.findFragmentById(R.id.frag_sensor_view);
为什么会这样? 另外我使用两个布局.xml文件。其中一个是sensor_main,由主代码调用,另一个是sensor_view。
我也把这些代码放在这里,这些也可能存在问题,因为我不明白两个布局xml文件怎么可能。
SENSOR_MAIN.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<fragment
android:id="@+id/frag_sensor_select"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="root.gast.playground.sensor.SensorSelectorFragment" />
<fragment
android:id="@+id/frag_sensor_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="root.gast.playground.sensor.SensorDisplayFragment" />
</LinearLayout>
SENSOR_VIEW.XML
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioGroup android:id="@+id/sensorRateSelector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<RadioButton android:id="@+id/delayFastest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SENSOR_DELAY_FASTEST"
android:checked="false"/>
<RadioButton android:id="@+id/delayGame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SENSOR_DELAY_GAME"
android:checked="false"/>
<RadioButton android:id="@+id/delayNormal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SENSOR_DELAY_NORMAL"
android:checked="true"/>
<RadioButton android:id="@+id/delayUi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SENSOR_DELAY_UI"
android:checked="false"/>
</RadioGroup>
<View android:id="@+id/seperator"
style="@style/line_separator"
android:layout_below="@id/sensorRateSelector" />
<TextView android:id="@+id/nameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/seperator"
android:layout_alignParentLeft="true"
android:text="Name:"
android:layout_marginRight="5dip" />
<TextView android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/nameLabel"
android:layout_alignTop="@id/nameLabel"
android:layout_alignBottom="@id/nameLabel" />
<TextView android:id="@+id/typeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/nameLabel"
android:layout_below="@id/nameLabel"
android:text="Type:"
android:layout_marginRight="5dip" />
<TextView android:id="@+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/typeLabel"
android:layout_alignTop="@id/typeLabel"
android:layout_alignBottom="@id/typeLabel"/>
<TextView android:id="@+id/maxRangeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/nameLabel"
android:layout_below="@id/typeLabel"
android:text="Max Range:"
android:layout_marginRight="5dip" />
<TextView android:id="@+id/maxRange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/maxRangeLabel"
android:layout_alignTop="@id/maxRangeLabel"
android:layout_alignBottom="@id/maxRangeLabel"/>
<TextView android:id="@+id/minDelayLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/maxRangeLabel"
android:layout_below="@id/maxRangeLabel"
android:text="Min Delay:"
android:layout_marginRight="5dip" />
<TextView android:id="@+id/minDelay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/minDelayLabel"
android:layout_alignTop="@id/minDelayLabel"
android:layout_alignBottom="@id/minDelayLabel"/>
<TextView android:id="@+id/powerLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/minDelayLabel"
android:layout_below="@id/minDelayLabel"
android:text="Power:"
android:layout_marginRight="5dip" />
<TextView android:id="@+id/power"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/powerLabel"
android:layout_alignTop="@id/powerLabel"
android:layout_alignBottom="@id/powerLabel"
android:layout_marginRight="5dip"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/power"
android:layout_alignTop="@id/power"
android:layout_alignBottom="@id/power"
android:text="mA"/>
<TextView android:id="@+id/resolutionLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/powerLabel"
android:layout_below="@id/powerLabel"
android:text="Resolution:"
android:layout_marginRight="5dip" />
<TextView android:id="@+id/resolution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/resolutionLabel"
android:layout_alignTop="@id/resolutionLabel"
android:layout_alignBottom="@id/resolutionLabel"/>
<TextView android:id="@+id/vendorLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/resolutionLabel"
android:layout_below="@id/resolutionLabel"
android:text="Vendor:"
android:layout_marginRight="5dip" />
<TextView android:id="@+id/vendor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/vendorLabel"
android:layout_alignTop="@id/vendorLabel"
android:layout_alignBottom="@id/vendorLabel"/>
<TextView android:id="@+id/versionLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/versionLabel"
android:layout_alignLeft="@id/vendorLabel"
android:layout_below="@id/vendorLabel"
android:text="Version:"
android:layout_marginRight="5dip" />
<TextView android:id="@+id/version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/versionLabel"
android:layout_alignTop="@id/versionLabel"
android:layout_alignBottom="@id/versionLabel"/>
<TextView android:id="@+id/accuracyLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/versionLabel"
android:layout_below="@id/versionLabel"
android:text="Accuracy:"
android:layout_marginRight="5dip" />
<TextView android:id="@+id/accuracy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/accuracyLabel"
android:layout_alignTop="@id/accuracyLabel"
android:layout_alignBottom="@id/accuracyLabel"/>
<!-- timestamp -->
<TextView android:id="@+id/timestampLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/accuracyLabel"
android:layout_below="@id/accuracyLabel"
android:layout_marginRight="5dip"
android:text="Timestamp:" />
<TextView android:id="@+id/timestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/timestampLabel"
android:layout_alignTop="@id/timestampLabel"
android:layout_alignBottom="@id/timestampLabel"
android:layout_marginRight="5dip"
android:visibility="gone" />
<TextView android:id="@+id/timestampUnits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/timestamp"
android:layout_alignTop="@id/timestamp"
android:layout_alignBottom="@id/timestamp"
android:visibility="gone"
android:text="(ns)" />
<TextView android:id="@+id/dataLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/accuracyLabel"
android:layout_below="@id/timestampLabel"
android:layout_marginRight="5dip"
android:visibility="gone"/>
<TextView android:id="@+id/dataUnits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/dataLabel"
android:layout_alignTop="@id/dataLabel"
android:layout_alignBottom="@id/dataLabel"
android:visibility="gone" />
<TextView android:id="@+id/singleValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/dataUnits"
android:layout_alignTop="@id/dataUnits"
android:layout_alignBottom="@id/dataUnits"
android:visibility="gone" />
<!-- X axis -->
<TextView android:id="@+id/xAxisLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/dataLabel"
android:layout_below="@id/dataLabel"
android:layout_marginRight="5dip"
android:visibility="gone"
android:text="@string/xAxisLabel" />
<TextView android:id="@+id/xAxis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/xAxisLabel"
android:layout_alignTop="@id/xAxisLabel"
android:layout_alignBottom="@id/xAxisLabel"
android:layout_marginRight="5dip"
android:visibility="gone" />
<!-- Y axis -->
<TextView android:id="@+id/yAxisLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/xAxisLabel"
android:layout_below="@id/xAxisLabel"
android:layout_marginRight="5dip"
android:visibility="gone"
android:text="@string/yAxisLabel" />
<TextView android:id="@+id/yAxis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/yAxisLabel"
android:layout_alignTop="@id/yAxisLabel"
android:layout_alignBottom="@id/yAxisLabel"
android:layout_marginRight="5dip"
android:visibility="gone" />
<!-- Z axis -->
<TextView android:id="@+id/zAxisLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/yAxisLabel"
android:layout_below="@id/yAxisLabel"
android:layout_marginRight="5dip"
android:visibility="gone"
android:text="@string/zAxisLabel" />
<TextView android:id="@+id/zAxis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/zAxisLabel"
android:layout_alignTop="@id/zAxisLabel"
android:layout_alignBottom="@id/zAxisLabel"
android:layout_marginRight="5dip"
android:visibility="gone" />
<!-- cos value (for rotation vector only) -->
<TextView android:id="@+id/cosLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/zAxisLabel"
android:layout_below="@id/zAxisLabel"
android:layout_marginRight="5dip"
android:visibility="gone"
android:text="cos(\u0398/2):" />
<TextView android:id="@+id/cos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/cosLabel"
android:layout_alignTop="@id/cosLabel"
android:layout_alignBottom="@id/cosLabel"
android:layout_marginRight="5dip"
android:visibility="gone" />
</RelativeLayout>
</ScrollView>
答案 0 :(得分:0)
如果没有看到您的清单,我无法100%回答,但我认为正在发生的事情是应用程序无法构建显示,因为它无法引用您的传感器碎片。以下是SensorDisplayFragment的包声明:
package com.example.sensorlistactivity;
所以要在xml文件中使用,你应该将它作为你的类:
class="com.example.sensorlistactivity.SensorDisplayFragment" />