-2

我需要在RelativeLayout的情況下找到線性佈局權重參數的替代品。相對佈局權重

下面是LinearLayout

LinearLayout.LayoutParams fp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,0); 
fp.weight = 2; 
FrameLayout parent_frame = (FrameLayout) findViewById(R.id.frame_container); 
parent_frame.setLayoutParams(fp); 

LinearLayout.LayoutParams tp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,0); 
tp.weight = 1; 
FrameLayout popup_layout = (FrameLayout) findViewById(R.id.popup_layout_id); 
popup_layout.setLayoutParams(tp); 

我需要做相同的,如果父佈局更改爲RelativeLayout代碼, 我有下面的代碼,但輸出是黑屏。

RelativeLayout.LayoutParams fp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,0); 
    //fp.weight = 2; 

    FrameLayout parent_frame = (FrameLayout) findViewById(R.id.frame_container); 
    parent_frame.setLayoutParams(fp); 

    RelativeLayout.LayoutParams tp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,0); 
    //tp.weight = 1; 

    FrameLayout popup_layout = (FrameLayout) findViewById(R.id.popup_layout_id); 
    popup_layout.setLayoutParams(tp); 

基本上我需要的是顯示2佈局垂直70%的第一佈局和與第二個30%屏幕,並且因爲它需要大量的代碼我不能在XML使用LinearLayout變化。

+0

你爲什麼不圍繞一個線性佈局內的相對佈局? –

回答