gloryhero 2015-10-18 11:42 采纳率: 50%
浏览 4438

自定义viewGroup中放入fragment view,但是fragment中的内容不显示

自定义viewGroup中放入fragment view,但是fragment中的内容显示不到界面上,明明fragment中的oncreateview都走了,而且返回的view不为空?求解!!!

<?xml version="1.0" encoding="utf-8"?>
android:id="@+id/test_viewgroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<TextView
    android:id="@+id/top"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/black"
    />
<!--<TextView
    android:id="@+id/bottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="sssssss"
    android:background="@android:color/white"
    />-->
<FrameLayout
    android:id="@+id/bottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</FrameLayout>

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_view_group);
//mBottomView = (TextView) findViewById(R.id.bottom);
//mViewGroup = (TestViewGroup) findViewById(R.id.test_viewgroup);
mTopView.setOnClickListener(this);
mBottomFragment = new BottomFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.bottom, mBottomFragment);
transaction.commit();
}

    public class BottomFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.test_sliding, container, false);
    return view;
}

}

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Log.i("edward", "onMeasure");
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// 测量子view的大小
//measureChildren(widthMeasureSpec, heightMeasureSpec);
}

@Override
protected void onLayout(boolean changed, int left, int top, int bottom, int right) {
    Log.i("edward", "onLayout");
    int width = getMeasuredWidth();
    int height = getMeasuredHeight();
    for(int i = 0; i < 2; i++) {
        View child = getChildAt(i);
        if (i == 0) {
            child.layout(0, 0, width, height / 2 - mOffset);
        }
        if (i == 1) {
            child.layout(0, height / 2 - mOffset, width, height);
        }
    }
}

fragment 布局中的东西显示不出来

  • 写回答

4条回答 默认 最新

  • bdmh 移动开发领域优质创作者 2015-10-18 11:56
    关注

    fragment用法和普通的view不太一样,你肯定没用对,找个博客学习一下

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog