2016-03-07 174 views
1

我是新的應用程序開發。滾動視圖裏面的一個片段不滾動

我使用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 –

回答

2

,滾動型

機器人添加此屬性:isScrollContainer = 「假」 並請LinerLayout到

WRAP_CONTENT

+0

另請添加android:fitsSystemWindows =「true」 – Jiks

0

,滾動型

添加此屬性

機器人:isScrollContainer = 「假」

,並請LinerLayout到

WRAP_CONTENT

+0

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

0

變化滾動視圖的高度來包裝內容

及其子佈局來包裝內容

那麼它會工作

<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

0

您不應該在另一個可滾動視圖中放置可滾動視圖。 (在你的例子中你有cardviewsscrollview)。

但是,如果您堅持這樣做,請檢查this answer。你可以設置固定的高度cardviews

它也可以爲listviews。見this blog如果你需要它

相關問題