好的,我不确定我在这里做错了什么。在查找了许多方向之后,我想出了这个片段,但我不确定它为什么不起作用。非常感谢您的解释和帮助。包括 LogCat 日志。
activity_camera.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".CameraActivity" >
<Button
android:id="@+id/buttonMenu"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/capture"
android:layout_alignBottom="@+id/capture"
android:layout_alignParentLeft="true"
android:layout_marginLeft="22dp"
android:text="menu" />
<Button
android:id="@+id/capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="24dp"
android:onClick="onClick"
android:text="Take pic" />
</RelativeLayout>
这是给我一个错误的片段
protected void onCreate(Bundle savedInstanceState) {
mPreferences = getSharedPreferences("CurrentUser", MODE_PRIVATE); mPreferences = getSharedPreferences("CurrentUser", MODE_PRIVATE);
super.onCreate(savedInstanceState);
RelativeLayout RL = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.activity_camera, null);
mTextureView = new TextureView(this);
mTextureView.setSurfaceTextureListener(this);
RL.addView(mTextureView);
setContentView(RL);
日志猫:
E/AndroidRuntime( 784): FATAL EXCEPTION: main
E/AndroidRuntime( 784): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
E/AndroidRuntime( 784): at android.widget.RelativeLayout$DependencyGraph.findRoots(RelativeLayout.java:1723)
E/AndroidRuntime( 784): at android.widget.RelativeLayout$DependencyGraph.getSortedViews(RelativeLayout.java:1670)
E/AndroidRuntime( 784): at android.widget.RelativeLayout.sortChildren(RelativeLayout.java:382)
E/AndroidRuntime( 784): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:403)
E/AndroidRuntime( 784): at android.view.View.measure(View.java:15848)
E/AndroidRuntime( 784): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
E/AndroidRuntime( 784): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
E/AndroidRuntime( 784): at android.view.View.measure(View.java:15848)
E/AndroidRuntime( 784): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
E/AndroidRuntime( 784): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
E/AndroidRuntime( 784): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
E/AndroidRuntime( 784): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
E/AndroidRuntime( 784): at android.view.View.measure(View.java:15848)
E/AndroidRuntime( 784): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
E/AndroidRuntime( 784): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
E/AndroidRuntime( 784): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2189)
E/AndroidRuntime( 784): at android.view.View.measure(View.java:15848)
E/AndroidRuntime( 784): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1905)
E/AndroidRuntime( 784): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1104)
E/AndroidRuntime( 784): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1284)
E/AndroidRuntime( 784): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
E/AndroidRuntime( 784): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
E/AndroidRuntime( 784): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
E/AndroidRuntime( 784): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
E/AndroidRuntime( 784): at android.view.Choreographer.doFrame(Choreographer.java:532)
E/AndroidRuntime( 784): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
E/AndroidRuntime( 784): at android.os.Handler.handleCallback(Handler.java:730)
E/AndroidRuntime( 784): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 784): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 784): at android.app.ActivityThread.main(ActivityThread.java:5103)
E/AndroidRuntime( 784): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 784): at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime( 784): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
E/AndroidRuntime( 784): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 784): at dalvik.system.NativeStart.main(Native Method)