我在我动态添加的相对布局周围放置了一个滚动视图。如果我将相对布局的高度设置为离开页面的固定量,则滚动视图将起作用。
例子:
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<RelativeLayout
android:id="@+id/llcustomrow"
android:layout_width="match_parent"
android:layout_height="800dp" >
</RelativeLayout>
</ScrollView>
但是我需要RelativeLayout 能够容纳我动态添加到其中的许多项目o 我将relativelayout 高度设置为wrap_content。但是,一旦我将足够的项目添加到相对布局中以使它们离开屏幕,则 Scrollview 不会注册
下面是我如何动态添加到相对布局
LinearLayout mLinearLayout;
RelativeLayout rlcopy;
RelativeLayout[] rArray = new RelativeLayout[20];
int counter = 0;
RelativeLayout llcustomrow;
RelativeLayout.LayoutParams paramsleft;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mLinearLayout = (LinearLayout) inflater.inflate(
R.layout.customworkout, container, false);
paramsleft = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
llcustomrow = (RelativeLayout)mLinearLayout.findViewById(R.id.llcustomrow);
for(int i = 0;i<=rArray.length-1;i++){
rArray[i] = (RelativeLayout)View.inflate(getActivity(), R.layout.addworkoutlayout, null);
paramsleft.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
paramsleft.setMargins(10, 0, 0, 0);
rArray[i].setLayoutParams(paramsleft);
}
Button bAdd = (Button) mLinearLayout.findViewById(R.id.bAddExcercise);
bAdd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
rArray[counter].setY(rArray[counter-1].getY() + (rArray[counter-1].getHeight() +25));
llcustomrow.addView(rArray[counter]);
counter++;
}
});
return mLinearLayout;
}
谢谢