简体   繁体   English

为什么FrameLayout被切断?

[英]Why FrameLayout is cut off?

I am trying to build a family tree pragmatically. 我正在尝试务实地建立家谱。 I have a frame layout which I am inflating with all tree nodes within a horizontal scroll view. 我有一个框架布局,正在使用水平滚动视图中的所有树节点进行充气。 I can see from the output that my tree is constructed. 从输出中可以看到我的树已构建。 however, the right edge is cut off for some reason. 但是,由于某些原因,右边缘被切断。

The XML layout 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>

Within activity code: I have added all tree nodes using the following approach through x and y co-ordinations 在活动代码中:通过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);
  • I am sure the cause is not the horizontal scroll view as I can see that the empty added view I have included for testing is displayed. 我确信原因不是水平滚动视图,因为我可以看到显示了已包含用于测试的空白添加视图。

  • I have tried putting the frame layout inside a linear layout as recommended by some blogger but that did not solve the problem 我曾尝试按照某些博主的建议将框架布局放入线性布局中,但这并不能解决问题

Any thoughts or suggestions are appreciated 任何想法或建议表示赞赏

I figured out the the frame layout dimensions were not updated. 我发现框架布局尺寸未更新。 i had to reset both height and width after finishing drawing. 完成绘图后,我不得不重新设置高度和宽度。

FrameLayout treeLayout = (FrameLayout) findViewById(R.id.treeLayout);
treeLayout.getLayoutParams().height = height;
treeLayout.getLayoutParams().width = width;
treeLayout.requestLayout();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM