我正在尝试使用Library SwipeLayout(https://github.com/daimajia/AndroidSwipeLayout)来创建一个可滑动行的表(即,实现this效果)。我想动态创建表(使用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并且IS大小合适,但它根本没有出现!
我知道SwipeLayout扩展了FrameLayout。是否有可能无法将GridLayout插入FrameLayout?
由于
答案 0 :(得分:0)
在RelativeLayout
内尝试FrameLayout
,然后在GridLayout
内添加RelativeLayout
。
希望这会对你有所帮助。