同时在相机活动中的新片段 - Android App

时间:2015-03-29 02:29:42

标签: android xml android-fragments android-activity camera

我想在我的相机活动中显示另一项活动,例如screenshot,这样您就可以在一个布局中看到两个活动。

我已阅读here我可以使用片段同时进行两项活动。但这对我没有用。我该怎么办呢?

我有两个LinearLayout,如下图所示。

camera_layout.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
  ....some buttons that worked.
</LinearLayout>

<LinearLayout
    android:id="@+id/TableLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <org.opencv.android.JavaCameraView
        android:id="@+id/java_camera"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <ImageView
        android:id="@+id/refImageView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="2" />

    <fragment
        android:id="@+id/my_fragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        class="com.hmkcode.android.MyFragment"/>
</LinearLayout> </LinearLayout>
  

我无法在camera_layout.xml中添加我的片段:

<fragment
    android:id="@+id/my_fragment"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    class="com.hmkcode.android.MyFragment"/>

我试图将此片段添加到我的camera_layout.xml中时出现此错误:

在moverio.imageprocess.CameraActivity.onCreate(CameraActivity.java:116)

如果没有这个是完美的。

发生在我的&#34; onCreate&#34;我尝试使用的方法:setContentView(R.layout.camera_layout);

这是我的fragment_layout.xml(只是一个例子,我试图使用它。):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099ff"
android:orientation="vertical" >

<TextView
    android:id="@+id/fragment_A_TextView"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_gravity="center_horizontal"
    android:layout_weight="3"
    android:gravity="center"
    android:text="Fragment A"
    android:textColor="#fff"
    android:textSize="20dp" />

<Button
    android:id="@+id/fragment_A_Button"
    android:layout_width="100dp"
    android:layout_height="0dp"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:text="Click A" /> </LinearLayout>

MyFragment.java:

public class MyFragment extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View view =  inflater.inflate(R.layout.fragment_layout, container, false);
    return view;
} }

非常感谢您的帮助。

0 个答案:

没有答案