相對佈局的底部我對Android非常新。我正在創建一個包含可點擊文本的應用程序。 所有可點擊的文本都存在於一個數組中,然後該數組與ListView
關聯,並顯示在RelativeLayout中。需要一個按鈕在Android
代碼是 -
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.main, R.id.label, contact_name));
ListView lv = getListView();
主要是相對佈局,標籤佈局中的文本框的id和CONTACT_NAME是去爲可點擊文本的數組。這一切工作正常。
最後,當數組非常大時,線性佈局變得可滾動。
現在我想限制這個列表佔用的區域佔總屏幕高度的80%或90%,並在底部預留一個按鈕,這將打開一個新的頁面/視圖。在相對佈局中包含按鈕是爲列表中的每個項目添加一個按鈕。更改相對佈局的高度正在改變列表中每個項目的高度。由此得出結論,數組中的每個項目都與整個相對佈局相關聯,並且相對佈局的數組來顯示所有項目。現在,如何通過將相對佈局列表限制在頂部屏幕的80%來在底部放置按鈕。
這是當前的XML文件的樣子的代碼
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btn"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Next"
/>
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/btn">
<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:textSize="16sp"
android:textStyle="bold" >
</TextView>
</ScrollView>
</RelativeLayout>
結束輸出爲隱藏的實際內容下一個按鈕的陣列。
這是我的Java代碼
// Make the contact number parameter accessible to member functions of List View
final String[] f_contact_number = contact_number;
// Binding Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.main, R.id.label, contact_name));
ListView lv = getListView();
// listening to single list item on click
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(f_contact_number[position]));
startActivity(intent);
}
});
Contact_number和contact_names兩個字符串數組,其上單擊CONTACT_NAME
Thanks
你能檢查一下代碼並告訴我我在做什麼錯?我嘗試了很多,但我得到的輸出是不希望的。 – user2550128