1
我想在屏幕上有兩個佈局。一個可滾動的,另一個應該包含一個按鈕,可以添加可滾動佈局的東西,並始終應該可見。我不確定我是否正朝着正確的方向前進,但到目前爲止,我已經擁有了這個功能,而且我的代碼工作方式並不令人期待。如果單擊buttonSPAddText
EditText與按鈕出現在同一行中。我希望它在另一個版式linearLayoutSPTextHolder
之下出現在它們下面。動態添加EditText到非兒童佈局的另一個LinearLayout
這是我的XAML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android"
p1:orientation="vertical"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/linearLayoutSPMain">
<LinearLayout
p1:orientation="horizontal"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="51.0dp"
p1:id="@+id/linearLayoutSPButtonHolder"
p1:layout_weight="1">
<Button
p1:text="AddText"
p1:layout_width="wrap_content"
p1:layout_height="match_parent"
p1:id="@+id/buttonSPAddText"
p1:layout_weight="1" />
<Button
p1:text="Do nothing"
p1:layout_width="wrap_content"
p1:layout_height="match_parent"
p1:id="@+id/buttonSPDoNth"
p1:gravity="center_vertical"
p1:layout_weight="1" />
</LinearLayout>
<ScrollView
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="@+id/scrollViewSPText"
p1:layout_weight="6">
<LinearLayout
p1:orientation="vertical"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="@+id/linearLayoutSPTextHolder"
p1:scrollbars="horizontal" />
</ScrollView>
</LinearLayout>
和我的活動:
namespace TiesaDrasaAndroid
{
[Activity (Label = "SelectPlayersActivity")]
public class SelectPlayersActivity : Activity
{
private int _textBoxId = 1000;
private LinearLayout _layout = null;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.SelectPlayers);
_layout = (LinearLayout)FindViewById(Resource.Id.linearLayoutSPTextHolder);
_layout.Orientation = Orientation.Vertical;
Button addPl = FindViewById<Button>(Resource.Id.buttonSPAddText);
addPl.Click += delegate {
this.CreateUserTextBox();
};
}
private void CreateUserTextBox()
{
var textbox = new EditText (this);
textbox.Id = _textBoxId;
textbox.SetWidth (100);
_textBoxId++;
_layout.AddView (textbox);
}
}
它的工作。 Thanx – valentasm 2014-10-18 09:23:47
歡迎您....你能接受嗎? – MohamedZaatari 2014-10-19 13:06:45
我是新來的。花了一些時間才知道如何接受它:D。當然在源代碼分析之後。 – valentasm 2014-10-19 13:24:09