繁体   English   中英

将片段添加到frameLayout:无法找到资源ID

[英]Add fragment to frameLayout: Unable to find resource ID

我必须在其中放入3个frameLayout动画,但必须使用片段,但是我使用的方法不起作用。 我在哪里做错了?

  11-28 11:18:41.979: E/AndroidRuntime(2263): java.lang.RuntimeException: Unable to start
  activity ComponentInfo{com.eni.mobilewf/com.eni.mobilewf.MenuActivity}: 
  android.content.res.Resources$NotFoundException: Unable to find resource ID #0x1

MenuActiviyt.java

 public class MenuActivity extends FragmentActivity {

 static final int NUM_ITEMS = 3;

 public static MenuActivity menuActivity = null;

  public static ViewPager mPager;
  private Interpolator interpolator = new LinearInterpolator();

 private int width;
 private int panel;
 long animationDuration = 1000;
 ThreeLayout layout;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);


    layout = new ThreeLayout(this, 3);
    layout.setAnimationDuration(1000);
    layout.setId(1234);

    layout.fl1.setId(0x11);
   layout.fl2.setId(0x22);
    layout.fl3.setId(0x33);

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();;
    Log.i("test", "transaction " +transaction);

    MenuFragment menu = new MenuFragment();
    ListFragment lista = new ListFragment();
     DetailFragment detail = new DetailFragment();

    Log.i("test", "id fl1 " +layout.fl1.getId());
    //id fl1 1
    Log.i("test", "id fl2 " +layout.fl2.getId());
    //id fl2 2
    Log.i("test", "id fl3 " +layout.fl3.getId());
    //id fl3 3
    transaction.add(layout.fl1.getId(), menu, "fragment1");

    transaction.add(layout.fl2.getId(), lista, "fragment2");

    transaction.add(layout.fl3.getId(), detail, "fragment3");

    transaction.commit(); 


    setContentView(layout);
    setupLayout();

}   

ThreeLayout.java

public class ThreeLayout extends RelativeLayout {

private int width;
private int panel;
public FrameLayout fl1;
public FrameLayout fl2;
public FrameLayout fl3;
long animationDuration = 800;

private Interpolator interpolator = new LinearInterpolator();

public ThreeLayout(final Context context, final float leftWeight) {
    super(context);
    fl1 = new FrameLayout(context);
    fl2 = new FrameLayout(context);
    fl3 = new FrameLayout(context);


    post(new Runnable() {
        @Override
        public void run() {
            width = getWidth();

            panel = (int) (width / leftWeight);


            _initWithDimentionsPortrait(context);
        }
    });

}

private void _initWithDimentionsPortrait(Context context) {



    RelativeLayout container = new RelativeLayout(context);
    LayoutParams containerParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    container.setLayoutParams(containerParams);


    containerParams.setMargins(0, 0, -width - panel, 0);
    Log.i("test", "la largezza è    "  +new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    container.addView(fl1);
    container.addView(fl2);
    container.addView(fl3);


    LayoutParams params1 = new LayoutParams(panel, LayoutParams.FILL_PARENT);
    LayoutParams params2 = new LayoutParams(width - panel, LayoutParams.FILL_PARENT);
    LayoutParams params3 = new LayoutParams(width - panel, LayoutParams.FILL_PARENT);

    fl1.setLayoutParams(params1);
    params2.addRule(RelativeLayout.RIGHT_OF, fl1.getId());

    fl2.setLayoutParams(params2);
    params3.addRule(RelativeLayout.RIGHT_OF, fl1.getId());

    fl3.setLayoutParams(params3);

    addView(container);
}

该片段未显示。

尝试将视图的资源ID设置为除六进制值以外的一些整数值,如下所示:

 layout.fl1.setId(1);
 layout.fl2.setId(2);
 layout.fl3.setId(3);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM