java-CWAC相机-实现自定义GUI

java-CWAC相机-实现自定义GUI,第1张

概述我正在使用Commonsware创建的库来制作一个简单的相机应用程序.在我的自述中,有一段说明了这一点:YoucansubclassCameraFragmentandoverrideonCreateView().ChaintothesuperclasstogettheCameraFragment’sownUI,thenwrapthatinyourowncontainerwith

我正在使用Commonsware创建的库来制作一个简单的相机应用程序.在我的自述中,有一段说明了这一点:

You can subclass CameraFragment and overrIDe onCreateVIEw(). Chain to
the superclass to get the CameraFragment’s own UI, then wrap that in
your own container with additional Widgets, and return the combined UI
from your onCreateVIEw().

我对Android Fragments仍然不太满意,所以我希望有人可以向我解释这一点.

我有两个活动(A,B),一个片段(CamFragment)和两个布局(A,B).我的第一个活动(A)加载一个具有单个按钮和imageVIEw的布局(A).该按钮将启动第二个活动(B),该活动将使用第二个布局(B)加载片段(CamFragment).第二个布局来自演示应用程序:

<FrameLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:tools="http://schemas.androID.com/tools"    androID:ID="@+ID/container"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    tools:context=".MainActivity"    tools:ignore="MergeRootFrame"/>

因此,现在在我的应用程序中,我希望在摄影机片段/第二个活动上有一个按钮,它将takePicture()onClick.按照自述文件中的说明,我需要首先对CameraFragment进行子类化.这很容易,我只是这样做:

public class CamFragment extends CameraFragment {

接下来,我必须重写onCreateVIEw.同样,这项琐碎的任务就像v9演示中一样.

  @OverrIDe  public voID onCreate(Bundle state) {    super.onCreate(state);    setHasOptionsMenu(true);    setHost(new DemoCameraHost(getActivity()));  }

下一部分是我真正感到困惑的地方,希望有人能提供帮助.

Chain to the superclass to get the CameraFragment’s own UI, then wrap
that in your own container with additional Widgets, and return the
combined UI from your onCreateVIEw().

我只是不完全确定这意味着什么.如果有一个演示,它展示了一个没有actionbar的自定义相机UI,那将是非常棒的,因为我觉得大多数开发人员都不会将控件放到Action bar中.

编辑#1:

@OverrIDepublic VIEw onCreateVIEw(LayoutInflater inflater, VIEwGroup container,        Bundle savedInstanceState) {    // Todo auto-generated method stub    VIEw uiFromParent=super.onCreateVIEw(inflater, container, savedInstanceState);    VIEw yourUi = inflater.inflate(R.layout.main_cam, container, false);    VIEw theThingThatwillHoldThePrevIEw = yourUi.findVIEwByID(R.ID.holder); // or whatever    ((VIEwGroup) theThingThatwillHoldThePrevIEw).addVIEw(uiFromParent); // with some appropriate LayoutParams    return super.onCreateVIEw(inflater, container, savedInstanceState);}

main_cam.xml

<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:tools="http://schemas.androID.com/tools"    androID:ID="@+ID/relativeLayout1"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:orIEntation="vertical" >    <FrameLayout        androID:ID="@+ID/holder"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:layout_alignParentBottom="true"        androID:layout_alignParentleft="true"        androID:layout_alignParenttop="true"        androID:layout_weight="1"        androID:background="@color/abs__bright_foreground_holo_dark"        androID:keepScreenOn="true"        tools:ignore="MergeRootFrame" >    </FrameLayout>    <Imagebutton        androID:ID="@+ID/button1"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_alignParentBottom="true"        androID:layout_centerHorizontal="true"        androID:layout_marginBottom="10dp"        androID:background="@color/abs__bright_foreground_holo_dark"        androID:src="@drawable/ic_launcher"        androID:text="Capture" /></relativeLayout>

cam_fragment.xml

<FrameLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:tools="http://schemas.androID.com/tools"    androID:ID="@+ID/container"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    tools:ignore="MergeRootFrame"/>

解决方法:

Next, I have to overrIDe onCreateVIEw. Again, a trivial task just like in the v9 demo.

您的代码未覆盖onCreateVIEw().它覆盖onCreate().

I’m just not entirely sure what that means/entails.

“绑定到超类以获得CameraFragment自己的UI”

VIEw uiFromParent=super.onCreateVIEw(inflater, container, savedInstanceState);

“然后用其他小部件将其包装在您自己的容器中”

VIEw yourUi=... // inflate something, create straight in Java, whateverVIEw theThingThatwillHoldThePrevIEw=yourUi.findVIEwByID(...); // or whatevertheThingThatwillHoldThePrevIEw.addVIEw(uiFromParent, ...); // with some appropriate LayoutParams

“并从onCreateVIEw()返回组合的UI”

return(yourUi);

总结

以上是内存溢出为你收集整理的java-CWAC相机-实现自定义GUI全部内容,希望文章能够帮你解决java-CWAC相机-实现自定义GUI所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1076137.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存