我有一个HorizontalScrollView与RelativeLayout和另一个相对布局,我添加动态视图。如果我添加一个使用布局膨胀器创建的视图,并且该视图大于屏幕,则不显示。
例如: View view1 = layoutInflater.inflate(R.layout.some_linear_layout, null, false);
RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(6000, 50);
lp1.leftMargin =500;
lp1.topMargin = 20;
view1.setLayoutParams(lp1);
parentRelativeLayout.addView(view1);
View view2 = new LinearLayout(getActivity());
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(6000, 50);
lp2.leftMargin =500;
lp2.topMargin = 20;
view2.setLayoutParams(lp2);
parentRelativeLayout.addView(view2);
在这种情况下,只有view2可见,而view1不可见。知道如何使view1出现吗?
父布局XML类似于:
<HorizontalScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/panel1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="200dp">
<RelativeLayout
android:id="@+id/panel2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="@color/black">
</.......
在添加子元素之前,我将panel1和panel2的宽度设置为8000px
显然是我的错
背景定义为
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
如果视图小于屏幕宽度
将其更改为(下),背景现在出现了
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/red" />
<corners android:radius="10dp" />
</shape>