让我们考虑一下这种情况。我们正在使用 Mortar 和 Flow 构建一个应用程序来简化事情,然后突然间我们发现我们可以使用一些旧的片段。这个片段有点复杂,所以我们想以某种方式将它们注入到我们的视图中。
如果我们有这样的 Mortar View,这是否可能:
<?xml version="1.0" encoding="utf-8"?>
<com.foo.myMortarView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="+id/mortar_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
<fragment
android:id="@+id/myFragment"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="match_parent"
class="com.example.MyFragment" >
</fragment>
</com.foo.myMortarView>
我们的片段是这样的:
public class MyFragment extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
/**
* Inflate the layout for this fragment
*/
return inflater.inflate(
R.layout.my_fragment, container, false);
}
}
这当然不是开箱即用的,那么我们该如何实现呢?谢谢!