我有一個Activity
包含ListView
根據SimpleCursorAdapter
和一個按鈕。 當我點擊按鈕時,我希望行高變大。 我決定按鈕OnClick
使用TextView
高度此:在代碼中設置ListView行高度
TextView tvRow = (TextView) findViewById(R.id.tvRow);
tvRow.setHeight(20);
,但它僅更改名單的第一行。
我可以更改Adapter
的getView
方法的高度:
TextView tvRow = (TextView) view.findViewById(R.id.tvRow);
tvRow.setHeight(20);
,但是這不是我所需要的功能;我需要按鈕OnClick
。
如何更改ListView
通過點擊按鈕來改變行高? 也許還有一招: 謝謝你的時間。
UPDATE:
當我把這個代碼在SimpleCursorAdapter
一切工作正常,但在方法getView
在BaseAdapter
:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = lInflater.inflate(R.layout.itemF, parent, false);
}
...
final LayoutParams params = view.getLayoutParams();
if (params == null) {
view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, mRowHeight));
}else {
params.height = mRowHeight; }
return view;
的列表中顯示只是忽略了這一點,它的行寬停留在相同。哪裏不對?
UPDATE:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/cbBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/llRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="5dp" >
<TextView
android:id="@+id/tvName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Наименование фирмы"
android:textAllCaps="true"
android:textSize="14dp" />
<TextView
android:id="@+id/tvAddr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Адрес фирмы"
android:textSize="10dp" />
</LinearLayout>
所以你想讓所有的行在你點擊按鈕時變大? – CaseyB
你的第二段代碼與你的第一段相同,這是一個錯字嗎? – Gix
是的,我希望所有的行都是相同的大小 - 更大或更小。 – Foenix