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

时间:2013-11-28 10:38:04

标签: android android-fragments compiler-errors android-framelayout

我有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);
}

片段未显示。谢谢提前

1 个答案:

答案 0 :(得分:0)

尝试将视图的资源ID设置为除hexa值之外的某个整数值,如下所示:

 layout.fl1.setId(1);
 layout.fl2.setId(2);
 layout.fl3.setId(3);
相关问题