如何动态地添加一个布局?布局、动态

2023-09-07 11:40:31 作者:22.在回忆里流浪

下面是我的XML

<TextView android:id="@+id/itemNameTextView"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:textColor="#000000" android:textSize="30sp" 
    android:layout_centerVertical="true" android:drawableLeft="@drawable/doller"
    android:drawablePadding="30dp" android:layout_marginLeft="30dp"/>

<Button android:id="@+id/buttonAdd"
    android:layout_width="wrap_content" android:layout_height="fill_parent"
    android:textColor="#000000" android:background="#00000000"
    android:layout_alignParentRight="true" android:layout_marginRight="10dp"
    android:text="ADD" android:textSize="25sp" android:textStyle="bold" />

<EditText android:id="@+id/displayPriceEditText"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="#000000" android:textSize="30sp" android:hint="0.00"
    android:layout_centerVertical="true" android:layout_toLeftOf="@id/buttonAdd"
    android:layout_marginRight="40dp" android:background="#00000000"/>

我应该能够添加一些文字无论是在EDITTEXT和TextView中,当我点击相同的布局已出现仅低于这一个(如列表)的按钮。任何人都可以请帮助我在这?

I should be able to add some text both in editText and textView and when i click the button the same layout has to appear just below this one( like a list ). Can anyone please help me on this?

推荐答案

有两个XML文件...行(row.xml),或者你要添加为一个视图什么都重复使用的东西是一个和看法,对此它需要被添加到另一个listbased.xml ......在第二个有一个按钮,所有其他的东西需要去....请确保您有listbased.xml里面父视图(相对,线性,列表视图)......或者类似的东西...

have two XMl files... the row (row.xml)or what ever reusable stuff you want to add as one view is one and the view to which it needs to be added to is another listbased.xml... in the second one have a button and all the other stuff that needs to go in.... Make sure that you have a parent view inside the listbased.xml(relative,linear,listview).... or something like that...

现在......在类...其中,这种方法需要被调用设置 R.setContentView(r.layout.listbased)......

now... in the class... where this method needs to be called set the R.setContentView(r.layout.listbased).... and

在这里你实现一个按钮侦听再加入吹气(例如:parentLayout.addView(mInflater.inflate(R.layout.row)))... ,其中

where you implement a button listener then add an inflater (ex:parentLayout.addView(mInflater.inflate(R.layout.row)))... where

公共LayoutInflater mInflater; 被定义为一个全球性的...

public LayoutInflater mInflater; is defined as a global...