【问题标题】: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。