0
我正在使用主題全息對話框的活動的Android項目。列表視圖與對話框主題活動底部的按鈕保持重疊
在對話框中,我有一個列表視圖,我想要的是始終顯示一個線性佈局,其中包含兩個相鄰的按鈕。列表視圖通過從呼叫日誌中檢索數據並填充列表的適配器來填充。
我遇到的問題是列表視圖始終顯示在頂部佔用整個對話框的底部按鈕,列表的內容與按鈕重疊。我希望列表位於線性佈局按鈕組頂部對話頂部的空間內。以下是主要內容視圖的代碼。這種佈局是使用的setContentView在onCreate方法
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
<LinearLayout android:id="@+id/call_log_select_host_button_group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<Button android:id="@+id/call_log_select_btnCancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Block"/>
<Button android:id="@+id/call_log_select_btnBlock"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>
設置,我不知道這有什麼差別,但以防萬一下面的是我如何填充列表和設置視圖。
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
CallInformation callInformation = (CallInformation)arrayList.get(position);
LayoutInflater inflator = (LayoutInflater)context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflator.inflate(R.layout.call_log_selection, parent, false);
ImageView imageView = (ImageView)rowView.findViewById(R.id.call_log_selector_image);
if (callInformation.type == android.provider.CallLog.Calls.INCOMING_TYPE)
{
imageView.setImageResource(android.R.drawable.sym_call_incoming);
}
else if (callInformation.type == android.provider.CallLog.Calls.OUTGOING_TYPE)
{
imageView.setImageResource(android.R.drawable.sym_call_outgoing);
}
else if (callInformation.type == android.provider.CallLog.Calls.MISSED_TYPE)
{
imageView.setImageResource(android.R.drawable.sym_call_missed);
}
CheckBox checkbox = (CheckBox)rowView.findViewById(R.id.call_log_selector_checkbox);
checkbox.setText(callInformation.content);
checkbox.setTag(callInformation.telephone);
return rowView;
}
}
下面的代碼是由適配器獲取視圖功能膨脹
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:id="@+id/call_log_selector_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:layout_gravity="center"
android:src="@android:drawable/stat_sys_phone_call"/>
<CheckBox android:id="@+id/call_log_selector_checkbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
感謝您的幫助,您可以提供的XML佈局。
請注意,「FILL_PARENT」已被棄用,「match_parent」應改爲使用。 – Jschools
@Jschools謝謝,這實際上是我在佈局問題中看到它時總是提到的一件事,但這次卻錯過了它。接得好! – codeMagic
是的,我確實將它作爲匹配父項,但將其更改爲fill_parent以防萬一,這是原因。我已經添加了layout_above行,但是現在該項目沒有編譯,因爲它說R.id.call_log_select_host_button_group是一個重複的字段。 – Boardy