[英]Making android listview layout scrollable
我有一個xml文件,其格式為ASCII格式:
---------------
| ImageView
--------------
| TextView
--------------
| List...
--------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.some.app"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/MovieCover"
android:layout_width="100dip"
android:layout_height="100dip"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:padding="10dp"
android:id="@+id/TextHeader"
android:background="#000000">
</TextView>
<ListView android:id="@+id/ListView02" android:layout_height="wrap_content"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
當我的ImageView和TextView占據屏幕的3/4以上時,我在顯示布局時遇到問題。 如何使用正在顯示的ListView使ImageView和TextView可滾動? 此時,只有要滾動的ListView,我希望整個布局可以滾動,就像它們本身就是一個頁面一樣。
我怎樣才能做到這一點?
您可以使用<ScrollView>
作為布局容器
沿着這條線的東西
<ScrollView>
<LinearLayout>
// your layout here
</LinearLayout>
</ScrollView>
我們內部需要LinearLayout的原因是ScrollView只能有一個直接子項
ListView具有addtoHeader和addtoFooter功能。 創建一個單獨的布局並將其添加到ListView的標題中。 在您的情況下,進行imageview和textview的相對布局,並將其添加到listview的標題中。 整個頁面將開始滾動。
Butter使用兩個LinearLayout和layoutweight="1"
並將ScrollView放在一個而listview放在另一個中
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- scroll view content -->
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<ListView android:id="@+id/ListView02" android:layout_height="wrap_content"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
如何將ImageView和TextView放在布局中並將此布局放在ScrollView中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.