在scrollview中回收查看

时间:2015-07-07 18:39:01

标签: android android-layout android-scrollview android-recyclerview

我创建了一个带有滚动视图的片段,其中包含循环视图。但是回收视图没有显示在视图中请帮我解决这个问题,有没有其他方法可以做到这一点。

这是我的layout.xml

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="8dp"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:paddingBottom="8dp"

        android:background="#FFFFFF">
    <ImageView
        android:id="@+id/productdetailpage_productimage"
        android:layout_width="400dp"
        android:layout_height="400dp"

        android:src="@drawable/product_image_menswear"
        android:background="#FFFFFF"/>
        <Button
            android:id="@+id/floatingbutton"
            android:layout_marginTop="390dp"
            android:layout_marginLeft="285dp"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/shareicon"/>
        <Button
            android:id="@+id/productdetailpage_share"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_marginTop="30dp"
            android:layout_marginLeft="300dp"

            android:background="@drawable/ic_share_grey600_18dp"
            />

        <Button
            android:id="@+id/productdetailpage_likebutton"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_marginTop="30dp"
            android:layout_marginLeft="50dp"

            android:background="@drawable/ic_favorite_outline_red_18dp"
           />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="65dp"
            android:layout_marginLeft="47dp"
            android:text="likes(20)"
            android:textSize="10dp"/>


        <View
            android:id="@+id/productdetailpage_separator2"
            android:layout_width="fill_parent"
            android:layout_height="2px"
            android:layout_below="@+id/productdetailpage_productimage"
            android:layout_marginBottom="2dp"
            android:layout_marginTop="15dp"
            android:background="#90909090"


            />
    <TextView
        android:id="@+id/productdetailpage_productname"
        android:layout_width="230dp"
        android:layout_height="wrap_content"
        android:text="Burton Maroon Casual"
        android:textColor="#000000"
        android:textSize="20dp"
        android:layout_marginTop="4dp"
        android:layout_marginLeft="8dp"

        android:layout_below="@+id/productdetailpage_separator2"
        />
        <TextView
            android:id="@+id/productdetailpage_price"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Rs.3000"
            android:textColor="#FB8C00"
            android:textSize="15dp"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="8dp"
            android:layout_below="@+id/productdetailpage_productname"
            />

        <View
            android:id="@+id/productdetailpage_separator3"
            android:layout_width="fill_parent"
            android:layout_height="2px"
            android:layout_below="@+id/productdetailpage_price"
            android:layout_marginBottom="2dp"
            android:layout_marginTop="15dp"
            android:background="#90909090"
            />
        <TextView
            android:id="@+id/productdetailpage_description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/productdetailpage_separator3"
            android:layout_marginTop="14dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_gravity="center_vertical"
            android:text="Look uber trendy and cool wearing this maroon  coloured shirt from the house of Burton. Made of cotton, this printed shirt for men will keep you sweat free and comfortable all day long. This snazzy casual shirt will be a perfect addition to your wardrobe."
            />

        <View
            android:id="@+id/productdetailpage_separator4"
            android:layout_width="fill_parent"
            android:layout_height="2px"
            android:layout_below="@+id/productdetailpage_description"
            android:layout_marginBottom="2dp"
            android:layout_marginTop="15dp"
            android:background="#90909090"
            />


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/availabestore_header"
            android:text="Available in 15 stores"
            android:layout_marginTop="14dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="14dp"
            android:textColor="@color/primaryColor"
            android:layout_below="@+id/productdetailpage_separator4"/>


        <android.support.v7.widget.RecyclerView
            android:paddingTop="8dp"
            android:id="@+id/available_storeslist_productpage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/availabestore_header"
            ></android.support.v7.widget.RecyclerView>
    </RelativeLayout>
    </ScrollView>

2 个答案:

答案 0 :(得分:1)

如果您希望在ScrollView内滚动浏览,则需要使用NestedScrollView

<android.support.v4.widget.NestedScrollView 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  ...
</android.support.v4.widget.NestedScrollView>

答案 1 :(得分:0)

这不是最好的表现,但如果你真的需要它,你应该使用NestedListView,正如@ianhanniballake所说。或者尝试this blog中描述的方式。