いくつかの UI 要素とリストビューを含む xml ファイルがあり、リストビューの上に relativelayout があります。リストビューをスクロールするときに、relativelayout が一緒にスクロールします。
1 に答える
4
使用できますListView.addHeaderView(View view)
。
この場合RelativeLayout
、xml から除外し、実行時に作成する必要があることに注意してください。また、 の前に呼び出すaddHeaderView
必要setAdapter
があります。
アップデート
RelativeLayout
別の xml ファイル (例: )に抽出するだけheader.xml
です。
<?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="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/orderMeal"
android:layout_marginLeft="20dip"
android:id="@+id/tv_restaurant_description_orderMeal"
android:drawableTop="@drawable/order_meal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/favorite"
android:layout_alignParentRight="true"
android:layout_marginRight="20dip"
android:drawableTop="@drawable/favorite"/>
</RelativeLayout>
そして、コードでそれを膨らませます:
lv_restaurantInformation = (ListView) findViewById(R.id.lv_restaurant_description_information);
lv_restaurantInformation.addHeaderView(LayoutInflater.from(this).inflate(R.layout.header, null));
于 2013-01-24T17:38:42.037 に答える