layout.xml中的机器人碎片



我一直试图让Roboguice处理布局文件中<fragment>块中声明的片段,然后将其注入到活动中,但是,尽管片段存在于屏幕外的某个位置(片段中的EditText会聚焦并引发事件),但它是不可见的。RoboGuice支持我在这里尝试做什么吗?还是我应该换一种方式?

代码:

<?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:orientation="vertical" >
    <fragment
        android:id="@+id/myFragment"
        android:name="com.example.MyFragment"
        android:layout_height="0dp"
        android:layout_width="0dp"
        android:layout_weight="1" >
        <!-- Preview: layout=@layout/my_fragment -->
    </fragment>
</LinearLayout>

Java:

@ContentView(R.layout.participant)
public final class Main extends RoboFragmentActivity {
  @Override
  protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  }
  @InjectFragment(R.id.myFragment) private MyFragment myFragment;
}

解决了这个问题,但对于其他人来说——手头的问题与RoboGuice完全无关,它允许如上所示的片段注入。相反,问题是我的片段的两个布局维度都设置为0dp,从而确保我的片段永远不会被渲染。

最新更新