滚动视图里面的一个片段不滚动

问题描述:

我是新的应用程序开发。滚动视图里面的一个片段不滚动

我使用3个选项卡。在每个片段中,我想显示cardview(7-8卡)的列表。

我的第一个fragment.xml之

<ScrollView 
android:layout_height="fill_parent" 
android:layout_width="match_parent" 
android:fillViewport="true" 

xmlns:android="http://schemas.android.com/apk/res/android" > 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:padding="10dp" 
    android:background="@color/white"> 

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="300dp" 
     android:id="@+id/crt1" 
     card_view:cardUseCompatPadding="true" 
     card_view:cardElevation="2dp" 
     card_view:cardCornerRadius="1dp" 
     android:clickable="true" 
     android:foreground="?attr/selectableItemBackground"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="3dp"> 

      <ImageView 
       android:layout_width="85dp" 
       android:layout_height="85dp" 
       android:src="@drawable/c_3musketeers" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:orientation="vertical"> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Three Musketeers" 
        android:textSize="25sp" /> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Rare | Air + Ground" 
        android:textSize="15sp" /> 
      </LinearLayout> 
     </LinearLayout> 
    </android.support.v7.widget.CardView> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Three Musketeers" 
     android:textSize="25sp" /> 

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="300dp" 
     android:id="@+id/crt2" 
     card_view:cardUseCompatPadding="true" 
     card_view:cardElevation="2dp" 
     card_view:cardCornerRadius="1dp" 
     android:clickable="true" 
     android:foreground="?attr/selectableItemBackground"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="3dp"> 

      <ImageView 
       android:layout_width="85dp" 
       android:layout_height="85dp" 
       android:src="@drawable/c_archers" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:orientation="vertical"> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Archers" 
        android:textSize="25sp" /> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Common | Air + Ground" 
        android:textSize="15sp" /> 
      </LinearLayout> 
     </LinearLayout> 
    </android.support.v7.widget.CardView> 

当我安装该AP它不滚动的。

我fragment.java文件

public class TroopsFragment extends Fragment { 

@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

    final ScrollView scrollview1 = (ScrollView) inflater.inflate(R.layout.troops, 
      container, false); 


    CardView cvt1; 
    cvt1 = (CardView) scrollview1.findViewById(R.id.crt1); 


    cvt1.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Toast.makeText(getActivity(), "tushar kalsara", 
        Toast.LENGTH_SHORT).show(); 
     } 
    }); 
    return scrollview1; 
}} 
+0

删除**机器人:方向= “垂直” * *来自ScrollView下方的linearlayout。 –

+0

之后,我该如何让我的列表垂直@amit vaghela –

,滚动型

机器人添加此属性:isScrollContainer = “假” 并请LinerLayout到

WRAP_CONTENT

+0

另请添加android:fitsSystemWindows =“true” – Jiks

,滚动型

添加此属性

机器人:isScrollContainer = “假”

,并请LinerLayout到

WRAP_CONTENT

+0

仍然无法正常工作@navneet sharma –

变化滚动视图的高度来包装内容

及其子布局来包装内容

那么它会工作

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:fillViewport="true" > 

<LinearLayout 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/white" 
    android:orientation="vertical" 
    android:padding="10dp" > 

    <android.support.v7.widget.CardView 
     android:id="@+id/crt1" 
     android:layout_width="match_parent" 
     android:layout_height="300dp" 
     android:clickable="true" 
     android:foreground="?attr/selectableItemBackground" 
     card_view:cardCornerRadius="1dp" 
     card_view:cardElevation="2dp" 
     card_view:cardUseCompatPadding="true" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="3dp" > 

      <ImageView 
       android:layout_width="85dp" 
       android:layout_height="85dp" 
       android:src="@drawable/c_3musketeers" /> 

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

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Three Musketeers" 
        android:textSize="25sp" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Rare | Air + Ground" 
        android:textSize="15sp" /> 
      </LinearLayout> 
     </LinearLayout> 
    </android.support.v7.widget.CardView> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Three Musketeers" 
     android:textSize="25sp" /> 

    <android.support.v7.widget.CardView 
     android:id="@+id/crt2" 
     android:layout_width="match_parent" 
     android:layout_height="300dp" 
     android:clickable="true" 
     android:foreground="?attr/selectableItemBackground" 
     card_view:cardCornerRadius="1dp" 
     card_view:cardElevation="2dp" 
     card_view:cardUseCompatPadding="true" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="3dp" > 

      <ImageView 
       android:layout_width="85dp" 
       android:layout_height="85dp" 
       android:src="@drawable/c_archers" /> 

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

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Archers" 
        android:textSize="25sp" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Common | Air + Ground" 
        android:textSize="15sp" /> 
      </LinearLayout> 
     </LinearLayout> 
    </android.support.v7.widget.CardView> 
</LinearLayout> 

这可能工作。 :)

+1

请添加细节到您的答案与代码剪辑,否则这将只是一个评论 – swiftBoy

您不应该在另一个可滚动视图中放置可滚动视图。 (在你的例子中你有cardviewsscrollview)。

但是,如果您坚持这样做,请检查this answer。你可以设置固定的高度cardviews

它也可以为listviews。见this blog如果你需要它