简体   繁体   中英

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

<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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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