2015-05-27 138 views
0

美好的一天。我有如下所示添加滚动视图后相对布局不滚动

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" > 

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     tools:context=".MainActivity"> 

     <include 
      android:id="@+id/toolbar" 
      layout="@layout/app_bar" /> 


     <android.support.v4.view.ViewPager 
      android:id="@+id/viewpager" 
      android:layout_width="match_parent" 
      android:layout_height="165dp" 
      android:layout_below="@+id/toolbar" /> 

     <RelativeLayout 
      android:id="@+id/relativeLayout" 
      android:layout_width="match_parent" 
      android:layout_height="25dp" 
      android:layout_alignBottom="@id/viewpager" 
      android:background="#33000000"> 

      <TextView 
       android:id="@+id/tv_image_description" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_centerVertical="true" 
       android:paddingLeft="10dp" 
       android:text="Shop Name" 
       android:textColor="#FFF" /> 


      <LinearLayout 
       android:id="@+id/ll_point_group" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" 
       android:orientation="horizontal" 
       android:paddingRight="10dp"> 

      </LinearLayout> 
     </RelativeLayout> 


     <android.support.v7.widget.RecyclerView 
      android:id="@+id/cardList" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/relativeLayout" /> 


    </RelativeLayout> 
</ScrollView> 

布局的代码,我连我的recyclerview数据的列表,但为什么RecyclerView布局是滚动的,但不是整个RelativeLayout的。我用ScrollView封装了RelativeLayout。它似乎不工作。请看下面的图片This is how to layout look like

请让我知道如果你们有更好的解决方案。十亿谢谢。

+0

您已设置'fill_parent'为相对以及滚动型 – SilentKiller

+0

@ user10908 one..It可以帮助...请尝试以下代码 –

+0

尝试添加此属性: android:descendantFocusability =“blocksDescendants”RelativeLayout –

回答

1

更改RelativeLayout高度WRAP_CONTENT

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    tools:context=".MainActivity"> 
1

您已加入另一人RecycleView一个滚动元件的滚动型 所以只有一个需要关注的焦点。这是违反android准则。你不应该把一个滚动组件放在另一个组件中。 但是同时实现滚动

yourRecycleView.setOnTouchListener(new OnTouchListener() { 
    // Setting on Touch Listener for handling the touch inside ScrollView 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
    // Disallow the touch request for parent scroll on touch of child view 
    v.getParent().requestDisallowInterceptTouchEvent(true); 
    return false; 
    } 
}); 
+0

有一个规则在stackoverflow,你应该发表评论,你为什么downvoted我的答案 –

+0

这里没有这样的规则。 –

+0

建议至少为downvoting给出一个合适的解释,以便我知道我做错了什么,而不仅仅是为了它,你有权downvote –

0

尝试这些你

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

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <include 
      android:id="@+id/toolbar" 
      layout="@layout/app_bar" /> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/viewpager" 
      android:layout_width="match_parent" 
      android:layout_height="165dp" 
      android:layout_below="@+id/toolbar" /> 

     <RelativeLayout 
      android:id="@+id/relativeLayout" 
      android:layout_width="match_parent" 
      android:layout_height="25dp" 
      android:layout_alignBottom="@id/viewpager" 
      android:background="#33000000" > 

      <TextView 
       android:id="@+id/tv_image_description" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_centerVertical="true" 
       android:paddingLeft="10dp" 
       android:text="Shop Name" 
       android:textColor="#FFF" /> 

      <LinearLayout 
       android:id="@+id/ll_point_group" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" 
       android:orientation="horizontal" 
       android:paddingRight="10dp" > 
      </LinearLayout> 
     </RelativeLayout> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/cardList" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/relativeLayout" /> 
    </RelativeLayout> 
    </ScrollView> 
</RelativeLayout> 
+0

@ user10908 ..它适用于你吗? ?? –

+0

不幸的是它不起作用。 – user10908

+0

哦对不起......给scroll_homeht wrap_content ...比它可能是可能的 –