【发布时间】:2016-11-12 16:23:40
【问题描述】:
XML 文件
<include
android:id="@id/my_toolbar"
layout="@layout/toobar"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/LinearEditTexts"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Title_input"
/>
<ImageButton
android:layout_height="wrap_content"
app:srcCompat="@android:drawable/ic_input_add"
android:id="@+id/imageButton2"
android:layout_width="50dp"
android:layout_gravity="bottom"
android:onClick="AddNewTextFields"
/>
</LinearLayout>
</ScrollView>
我以编程方式制作 EdtTexts 的 Java 文件 列出所有edittexts = new ArrayList();
public void AddNewTextFields(View view) {
TotalEdittexts++;
if (TotalEdittexts > 100)
return;
EditText editText = new EditText(this);
Containerlayout.addView(editText);
editText.setGravity(Gravity.TOP);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) editText.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
editText.setLayoutParams(layoutParams);
//if you want to identify the created editTexts, set a tag, like below
editText.setTag("AddedEditText" + TotalEdittexts);
alledittexts.add(editText);
}
每次onClickListener() 调用该函数时,我都试图让我的图像按钮位于由该图像按钮创建的EditText 下方。
设置它的重力并没有改变任何我想在这方面获得帮助的东西。
【问题讨论】:
标签: android android-linearlayout android-scrollview android-imagebutton