片段不会改变textview的大小

时间:2013-08-27 17:46:02

标签: android android-fragments

我有一个事件应该改变我的新片段中textview的大小我创建的textview是在我的新片段和我的旧片段共享的相对布局中创建的:

     Fragment1 rightFragment;
    rightFragment = new Fragment1();
    Bundle args = new Bundle();
    args.putInt("args", arguments);
    rightFragment.setArguments(args);
    android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager()
            .beginTransaction();
    transaction.replace(R.id.fragment_container, rightFragment);
    transaction.addToBackStack(null);
    transaction.commit();
    TextView textView = (TextView) findViewById(R.id.text);
    textView.setTextSize(settings.getFloat("size", 24.0f));

当我在我的活动中执行此代码时,旧的相对布局中的textView被更改,而不是新的。如何在新布局中使textView工作?

2 个答案:

答案 0 :(得分:1)

在动态设置时,您还需要在新布局中设置textview大小。您可以使用float变量来保存textsize的新值,然后将其传递给新的片段。

您可以这样做:

Float textsize = 24.0f;
textView.setTextSize(settings.getFloat("size", textsize));

答案 1 :(得分:1)

您可以使用大小向片段发送参数,然后在活动的onCreateView方法中设置textView大小。