2013-11-28 45 views
0

我有3 frameLayout在这些动画我必须放碎片,但我使用的方法不起作用。我在哪里做错了?添加片段到frameLayout:无法找到资源ID

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

片段无法预先shown.Thanks

回答

0

尝试设置你的看法资源ID为一些整数值除六进制值如下:

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

我得到相同的错误 –

+0

你是否更改过ID? – GrIsHu

+0

是的,我改变了整数 –