1

我一直试图让 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>

爪哇:

@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;
}
4

1 回答 1

1

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

于 2012-03-08T19:20:40.663 回答