简体   繁体   English

Android布局-制作可滚动布局

[英]Android Layout - Making scrollable layout

I have a ListView and an ImageView contained in a LinearLayout. 我在LinearLayout中包含一个ListView和一个ImageView。 Unfortunately, ListView doesn't scroll the ImageView together with it. 不幸的是,ListView不会将ImageView与其一起滚动。

I've tried to use ScrollView to wrap both components, but there is a problem with ListView if I did so. 我尝试使用ScrollView来包装两个组件,但是如果这样做,ListView会出现问题。

Anyone know how to make all of the components inside LinearLayout scroll? 有谁知道如何使LinearLayout中的所有组件滚动?

Here is my layout xml: 这是我的布局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>

Here is the screenshot of how it looks right now: 这是它现在的外观的屏幕截图:

滚动视图和列表视图

You can make your ImageView in another layout file, inflate it and add as HeaderView. 您可以将ImageView放在另一个布局文件中,对其进行充气并添加为HeaderView。

For example: 例如:

View header = LayoutInflater.from(this).inflate(R.layout.your_imageview_layout, null);
yourListView.addHeader(header, null, false);

You should try to set your image as header of your list. 您应该尝试将图像设置为列表的标题。

Use the following function to do this: 使用以下功能可以做到这一点:

yourListView.addHeaderView(yourImageView, null, false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM