[英]Android Layout - Making scrollable layout
我在LinearLayout中包含一個ListView和一個ImageView。 不幸的是,ListView不會將ImageView與其一起滾動。
我嘗試使用ScrollView
來包裝兩個組件,但是如果這樣做,ListView會出現問題。
有誰知道如何使LinearLayout中的所有組件滾動?
這是我的布局xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imgCanvas"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/imgCanvas"
android:smoothScrollbar="true" />
</LinearLayout>
這是它現在的外觀的屏幕截圖:
您可以將ImageView放在另一個布局文件中,對其進行充氣並添加為HeaderView。
例如:
View header = LayoutInflater.from(this).inflate(R.layout.your_imageview_layout, null);
yourListView.addHeader(header, null, false);
您應該嘗試將圖像設置為列表的標題。
使用以下功能可以做到這一點:
yourListView.addHeaderView(yourImageView, null, false);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.