我使用自定義佈局來顯示首選項,以便我可以在屏幕底部插入廣告條。這個想法是讓橫幅貼在頁面的底部,並在滾動視圖中顯示屏幕的其餘部分。 我的偏好設置的高度有問題。 我目前在下面的XML佈局中將其硬編碼爲「2000dip」。Android:自定義首選項屏幕大小問題
它工作正常,橫幅停留在底部,在可滾動視圖頂部的喜好。
但是,硬編碼的高度值不好,我希望它自動設置爲偏好所採用的確切高度,因爲它目前太短或太長(在偏好之後有空白區域)。 我試圖用wrap_content或fill_parent替換硬編碼值,但沒有成功。 有什麼想法?
在我PreferenceActivity我已經包含以下兩行:
setContentView(R.layout.preferences_scrollable);
addPreferencesFromResource(R.layout.preferences);
而且我定義的XML文件preferences_scrollable.xml佈局preferences_scrollable:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
android:id="@+id/pref_scrollable_sv">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical"
android:id="@+id/pref_scrollable_ll">
<ListView android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_height="2000dip">
</ListView>
</LinearLayout>
</ScrollView>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical">
<com.google.ads.AdView android:id="@+id/ad"
ads:adSize="BANNER" android:layout_width="fill_parent"
ads:loadAdOnCreate="true" ads:adUnitId="xxx"
android:layout_height="wrap_content"
android:layout_weight="0"/>
</LinearLayout>
</LinearLayout>
nope,沒有做任何事情...... – muslidrikk