我正在努力以实用的方式构建一个家谱。我有一个框架布局,我正在水平滚动视图中的所有树节点充气。我可以从输出中看到我的树是构造的。但是,由于某种原因,右边缘被切断了。
XML布局
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="@+id/id">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fillViewport="true"
android:id="@+id/treeLayout">
<TextView
android:text="Go ahead and add your family members"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:id="@+id/instructionTxt" />
</FrameLayout>
<View
android:layout_width="200dp"
android:layout_height="50dp"/>
</LinearLayout>
</HorizontalScrollView>
在活动代码中: 我通过x和y协调使用以下方法添加了所有树节点
ViewGroup layout = (ViewGroup) findViewById(R.id.treeLayout);
View view = LayoutInflater.from(this).inflate(R.layout.tree_node, layout,false);
view.setX(xPosition);
view.setY(yPosition);
layout.addView(view);
我确定原因不是水平滚动视图,因为我可以看到我已经包含的用于测试的空白添加视图。
我已经尝试按照一些博主的建议将框架布局放在线性布局中但是没有解决问题
感谢任何想法或建议
答案 0 :(得分:0)
我发现框架布局尺寸没有更新。完成绘图后我不得不重置高度和宽度。
FrameLayout treeLayout = (FrameLayout) findViewById(R.id.treeLayout);
treeLayout.getLayoutParams().height = height;
treeLayout.getLayoutParams().width = width;
treeLayout.requestLayout();