我为活动创建了一个布局文件.在这个布局中,我创建了一个带有textview和edittext的LinearLayout.现在我想创建额外的LinearLayouts,它将查看并包含与原始LinearLayout完全相同的视图,但具有不同的文本.我还想在运行期间以编程方式执行此操作,因为这些LinearLayout的数量在运行之间会有所不同.我已经阅读了一些关于inflaters的内容,但我对它们的理解并不充分.
我在想这样的事情,显然代码是错误的,但希望你明白我想做什么:
LinearLayout llMain = (LinearLayout)findViewById(R.id.mainLayout);
LinearLayout llToCopy = (LinearLayout)findViewById(R.id.linearLayoutToCopy);
for(int player = 0; player < size; player++)
{
LinearLayout llCopy = llToCopy.clone();
TextView tv = (TextView)llCopy.getChildAt(0);
tv.setText(players.get(player).getName());
llMain.addView(llCopy);
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个包含3个列表视图的相对布局.在顶部,我有一个editText字段.在中间有一个滚动视图填充所有剩余空间.在底部我放了一个按钮.问题是,当我在editText字段中输入时,键盘会显示,然后按钮被移动并放在键盘的顶部.似乎按钮总是粘在视图的底部"左",但我希望它保持在原始窗口的底部.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/ll_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<TextView
android:id="@+id/tv_course_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_view_course_name"
android:textStyle="bold" />
<EditText
android:id="@+id/et_course_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_save_course_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="saveCourse"
android:text="@string/button_save_course" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_course_table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/ll_save_course_button"
android:layout_below="@id/ll_name" >
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)