想要在頁面上有一個固定的標題,但我不能。Android:固定標題在頂部
我這樣做: 代碼XML [fragment_products.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="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Headerrrr"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
<ScrollView
android:id="@+id/sw_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/sw_linear_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/list_background"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:textColor="#43bd00"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/qtde"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="2dip"
android:textColor="#acacac" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
JAVA代碼(FindProductsFragment):
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
/**
* Updating parsed JSON data
* */
String[] sr = { TAG_NAME, TAG_QTDE };
int[] in = { R.id.name, R.id.qtde };
ListAdapter adapter = new SimpleAdapter(getActivity(), productsList, R.layout.fragment_products, sr, in);
setListAdapter(adapter);
}
結果不是我想要的。
希望有固定的頭。 任何想法該怎麼辦?
我試着照你說的去做,但沒有奏效。 – ACosta
你應該在這兩個視圖之間放置其他佈局元素。而且你應該在兩者之間調整它們。就是這樣。我在我的應用程序中使用這種方式,並沒有遇到任何問題。 – denizt