繁体   English   中英

Android-在FrameLayout中添加GridLayout

[英]Android - Adding a GridLayout inside a FrameLayout

我正在尝试使用Library SwipeLayout( https://github.com/daimajia/AndroidSwipeLayout )来制作可滑动行的表格(即达到这种效果)。 我想动态创建表(使用Java,而不是xml)。 该表(如果它以xml形式存在)应如下所示:

...TableLayout...
<TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="0dp">

                <com.daimajia.swipe.SwipeLayout
                    android:id="@+id/swipe"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <!-- The first view in SwipeLayout is the delete button hidden behind -->
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="#FFFFFF"
                        android:id="@+id/delete1"
                        android:gravity="center"
                        android:padding="16dp"
                        android:background="#FF0000"
                        android:textSize="22sp"
                        android:text="Delete"/>

                    <GridLayout android:layout_height="wrap_content"
                            android:layout_width="fill_parent"
                            android:background="@drawable/bottom_border_light_solid"
                            android:columnCount="2"
                            android:padding="10dp">

                        ...TextViews...

                    </GridLayout>

                </com.daimajia.swipe.SwipeLayout>

            </TableRow>
.../TableLayout...

我的表创建代码如下所示:

TableRow row = new TableRow(c);
SwipeLayout swipeLayout = new SwipeLayout(c);
TextView delete = generateDeleteButton(c); //I have confirmed that this function works
GridLayout cell = generateRoutineLayout(c); //I have confirmed that this function works

swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
swipeLayout.addDrag(SwipeLayout.DragEdge.Left, delete);
swipeLayout.addSwipeListener(swipeListener);

cell.setPadding(5, 5, 5, 5);

swipeLayout.addView(delete);
swipeLayout.addView(cell);

TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
swipeLayout.setLayoutParams(lp);

row.addView(swipeLayout);
TableRow.LayoutParams rl = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
row.setLayoutParams(rl);//TableRow.LayoutParams.WRAP_CONTENT));
row.setPadding(0, 0, 0, 0);

我已经确认generateRoutineLayout(c)可以正常工作并生成正确的GridLayout。 在Android监视器中仔细检查“树状视图”后,很明显,网格布局已添加到SwipeLayout中,并且大小正确,但根本没有出现!

我知道SwipeLayout扩展了FrameLayout。 是否有可能无法将GridLayout插入FrameLayout?

谢谢

尝试将RelativeLayout放在FrameLayout ,然后将GridLayout添加到RelativeLayout

希望这对您有帮助。

暂无
暂无

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

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