2016-04-28 212 views
0

我正在创建一个应用程序。并且用户信息以相对布局显示。在相对布局下是用户创建的项目的列表视图。我希望如果您在列表视图中向下滚动,相对布局向上滚动并最终消失,并且列表视图在整个屏幕上拉伸。向上滚动时向上滚动listview

像你在facebook上的应用程序。 Facebook Scrolling image

我如何做到这一点,这是我的布局文件:

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

 
    <LinearLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:orientation="vertical"> 
 

 
     <RelativeLayout 
 
      android:layout_width="match_parent" 
 
      android:layout_height="0dp" 
 
      android:layout_weight="6"> 
 

 
      <ImageView 
 
       android:id="@+id/BackgroundPictureOther" 
 
       android:layout_width="match_parent" 
 
       android:layout_height="150dp" 
 
       android:background="#eeeeee" /> 
 

 

 
      <ImageView 
 
       android:id="@+id/profileOther" 
 
       android:layout_width="100dp" 
 
       android:layout_height="100dp" 
 
       android:background="#444444" 
 
       android:scaleType="fitXY" 
 
       android:layout_gravity="center_horizontal" 
 
       android:layout_alignParentBottom="true" 
 
       android:layout_centerHorizontal="true" 
 
       android:layout_marginBottom="40dp"/> 
 

 
      <TextView 
 
       android:id="@+id/profileName" 
 
       android:layout_width="wrap_content" 
 
       android:minWidth="150dp" 
 
       android:layout_centerHorizontal="true" 
 
       android:textColor="#aaa" 
 
       android:textAlignment="center" 
 
       android:textSize="30sp" 
 
       android:layout_height="wrap_content" 
 
       android:layout_alignParentBottom="true" 
 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 
 

 
     </RelativeLayout> 
 

 
     <ListView 
 
      android:layout_width="match_parent" 
 
      android:layout_height="0dp" 
 
      android:layout_weight="8"></ListView> 
 
    </LinearLayout> 
 

 
</merge>

提前感谢!

回答

0

你有2个选择这里:

1)你应该把里面NestedScrollView您的整个布局和改变的ListView成RecyclerView。

2)或者你可以使用个人资料图片设置你的布局作为listview的标题视图。 为此,您需要将您的布局与其他xml布局文件中的配置文件放在一起,然后在代码中充气并使用listview.addHeaderView(查看v)

+0

谢谢,通过使用addHeader它完美地工作! –