【发布时间】:2016-10-02 22:03:25
【问题描述】:
当我单击主活动中的按钮时,我需要在垂直滚动中动态创建垂直线性布局。线性布局的行数必须与主 Activity 的编辑文本中指示的一样多。
我现在如何创建具有线性布局的片段和按下按钮时的滚动,但我不知道如何根据主活动的编辑文本的值用按钮填充这个线性布局。
图解说明:
我有这个代码:
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>
【问题讨论】:
-
可以使用 ListView 或 RecyclerView。 LinearLayout 只是您需要使用自定义适配器实现列表的布局格式
标签: android button scroll fragment android-linearlayout