0
当我点击主活动中的按钮时,需要在垂直滚动条内动态创建垂直线性布局。线性布局必须具有主活动编辑文本中指示的行数。Android:创建一个包含可变元素的片段
我现在如何创建带线性布局的片段和按下按钮时的滚动,但我不知道如何使用按钮来填充此线性布局,具体取决于主活动的编辑文本的值。
图形的解释:
我有这样的代码:
public void onAdd(View view) { // This is the method called when button is clicked
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
BlankFragment fragment = new BlankFragment();
transaction.add(R.id.table2,fragment);
transaction.commit();
}
这是片段的XML代码:
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.example.xxxxx.yyyyy.BlankFragment">
<ScrollView
android:id="@+id/sv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/ll6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Buttons go here -->
</LinearLayout>
</ScrollView>
非常感谢:) !! – Sergio
它可以与ListView或RecyclerView。 LinearLayout只是您需要使用自定义适配器实现列表的布局格式 – androidXP