【问题标题】:Scrollable ImageView with ListView带有 ListView 的可滚动 ImageView
【发布时间】:2016-05-25 13:28:17
【问题描述】:

我有一个 ImageView,即封面照片。另一个 ImageView 即个人资料图片和一个 textview 即 Coverphoto 中的名称。这张封面照片下方有一个列表视图。我想让整个布局可滚动,即封面照片布局也应该使用 Listview 向上滚动。我试过 list.addHeaderView 但如何将封面照片与 list.addheaderview 中的个人资料照片和名称合并?

【问题讨论】:

标签: android listview android-imageview


【解决方案1】:

将所有这些(封面照片、个人资料照片、姓名等)放在一个布局中(例如LinearLayout | RelativeLayout),然后将它们充气并添加到您的Listview

你的代码可能是这样的:

View profielView = LayoutInflater.from(getActivity()).inflate(R.layout.view_your_profile, mListView, false);
mListView.addHeaderView(profileView);

您的view_your_profile 是这样的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_profile_header_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- cover photo -->
    <ImageView
        android:id="@+id/image_profile_cover"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/ic_launcher"
        android:scaleType="centerCrop" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal">
            <!-- username  -->
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginRight="8dp"
                android:text="@string/icon_chevron_left"
                android:textColor="@color/white_transparent_30" />

            <!-- profile photo -->
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"/>

        </LinearLayout>

</RelativeLayout>

还有更好的方法使用 RecyclerView 和不同的视图类型,你可以找到很好的教程 here

【讨论】:

    【解决方案2】:

    您需要为您的封面照片制作一个RelativeLayout,并将个人资料图片和textview放入其中,例如在一个名为header.xml的文件中。

    你可以参考这些问题:

    Android, ImageView over ImageView

    Adding text to ImageView in Android

    因此,在制作完 header.xml 后,您可以将其与封面照片、个人资料图片、文本一起添加到 ListView,它会在您滚动列表视图时滚动!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-19
      相关资源
      最近更新 更多