【发布时间】:2016-11-13 06:34:03
【问题描述】:
我正在尝试创建一个新的表格行并将其添加到现有的表格布局中。我已经搜索了互联网,似乎我已经尝试了所有方法,但我无法显示新行。如果我在布局中添加一个带有 id 的 TableRow 并将我的自定义 ImageView 添加到其中而不将新的 TableRow 添加到 ImageView 显示的布局中,但我需要动态添加一个新行。在我的片段中:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_default_view,
container, false);
final ViewGroup tableLayout = (ViewGroup) rootView.findViewById
(R.id.table_bracket);
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT
);
TableRow tableRow = new TableRow(context);
tableRow.setLayoutParams(layoutParams);
SeparatorImageView separator = new SeparatorImageView(getActivity());
separator.setLayoutParams(layoutParams);
tableRow.addView(separator);
tableLayout.addView(tableRow);
return rootView;
}
这是我要添加到的布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mbusby.bracketsandbox.DefaultViewFragment">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/table_bracket"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:stretchColumns="*">
</TableLayout>
【问题讨论】:
标签: android android-studio tablerow