我使用文本編輯創建搜索佈局以輸入關鍵字,列表視圖顯示搜索結果以及按鈕「添加聯繫人」。 我想用這裏的條件來構建這個佈局: 首先,如果我設置List View的可見性是GONE(當我開始Activity並且我還沒有使用搜索操作),我想要顯示Button「add contact」bellow文本編輯。 接下來,當我使用搜索操作和接收結果時,我想要顯示列表視圖下面的文本編輯和按鈕「添加聯繫人」將被移動到佈局的底部。 這裏是我的xml:如何使用列表視圖下方的按鈕構建佈局
<LinearLayout
android:id="@+id/search_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/topcontrolbar"
android:background="@drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/searchbar"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="15dp"
android:background="@color/transparent" >
<Button //This is button Search
android:id="@+id/magnifier"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="13dp"
android:background="@drawable/search_button" />
<EditText
android:id="@+id/edt_key_search"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/magnifier"
android:background="@color/white"
android:hint="@string/contactadd3"
android:imeOptions="actionSearch"
android:inputType="text"
android:paddingLeft="5dp"
android:singleLine="true"
android:textSize="16sp" >
</EditText>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/transparent" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
>
</ListView>
<Button
android:id="@+id/btnRegi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="13dp"
android:layout_marginRight="13dp"
android:layout_bellow="@+id/listView1"
android:background="@drawable/registerbutton"
android:text="@string/contactadd2"
android:textColor="#FAFAFA" />
</RelativeLayout>
</LinearLayout>
我的問題是:這是確定當我開始活動時,下面的EditText按鈕btnRegi。但是當我收到結果並設置爲列表視圖時,列表視圖將顯示填充佈局以及按鈕btnRegi消失。
任何人都可以幫助我嗎?
對不起,我的英語不好,希望你們能看到我的問題。謝謝
'機器人:layout_bellow = 「@ + ID/ListView1的」'錯字這裏的錯誤是'below'不'bellow'。你可以使用一個相對佈局 – Raghunandan
對不起,這是我的錯誤,因爲我在這篇文章中編輯。 –