2016-12-24 42 views
1

我一直在研究一個應用程序,但卡在xml佈局問題中,當我在線性佈局內使用卡片視圖時,通常使用的scrollview不起作用,我在Google中查找並發現了關於NestedScrollview,它仍然不會工作,應用程序的力量關閉,有人可以告訴我我到底做錯了什麼,是正確的。這將是非常有益的。Scrollview不適用於Cardview

activity_items_details.xml

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="5dp" 
    app:cardElevation="5dp"> 

    <TextView 
     android:id="@+id/tvItemDetailsName" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:textSize="32sp" 
     android:paddingTop="65dp" 
     android:paddingBottom="65dp" 
     tools:text="Item Name" 
     android:textAllCaps="true" 
     android:textStyle="bold" /> 

</android.support.v7.widget.CardView> 


    <android.support.v7.widget.CardView> 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp"> 

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

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Qty" 
       android:textSize="16sp" 
       android:padding="10dp" 
       android:textColor="@android:color/black"/> 

      <TextView 
       android:id="@+id/tvItemDetailsQty" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       tools:text="Qty:" 
       android:textSize="18sp" 
       android:layout_gravity="center"/> 

     </LinearLayout> 

    </android.support.v7.widget.CardView> 

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="PO #" 
       android:textSize="16sp" 
       android:padding="10dp" 
       android:paddingRight="5dp" 
       android:textColor="@android:color/black"/> 

      <TextView 
       android:id="@+id/tvItemDetailsPono" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       tools:text="PO #:" 
       android:textSize="18sp" 
       android:layout_gravity="center"/> 

     </LinearLayout> 

    </android.support.v7.widget.CardView> 

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Supplier" 
       android:textSize="16sp" 
       android:padding="10dp" 
       android:paddingRight="5dp" 
       android:textColor="@android:color/black"/> 

      <TextView 
       android:id="@+id/tvItemDetailsSupplier" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       tools:text="Supplier:" 
       android:textSize="18sp" 
       android:layout_gravity="center"/> 

     </LinearLayout> 

    </android.support.v7.widget.CardView> 

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp" 
     android:layout_gravity="center"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Contact" 
       android:textSize="16sp" 
       android:padding="10dp" 
       android:paddingRight="5dp" 
       android:textColor="@android:color/black"/> 

      <TextView 
       android:id="@+id/tvItemDetailsContact" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       tools:text="Contact:" 
       android:textSize="18sp" 
       android:layout_gravity="center"/> 

     </LinearLayout> 


    </android.support.v7.widget.CardView> 

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Transporter" 
       android:textSize="16sp" 
       android:padding="10dp" 
       android:paddingRight="5dp" 
       android:textColor="@android:color/black"/> 

      <TextView 
       android:id="@+id/tvItemDetailsTransport" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       tools:text="Transporter:" 
       android:textSize="18sp" 
       android:layout_gravity="center"/> 

     </LinearLayout> 

    </android.support.v7.widget.CardView> 

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="LR #" 
       android:textSize="16sp" 
       android:padding="10dp" 
       android:paddingRight="5dp" 
       android:textColor="@android:color/black"/> 

      <TextView 
       android:id="@+id/tvItemDetailsLrno" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       tools:text="LR #:" 
       android:textSize="18sp" 
       android:layout_gravity="center"/> 

     </LinearLayout> 

    </android.support.v7.widget.CardView> 

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="LR #" 
       android:textSize="16sp" 
       android:padding="10dp" 
       android:paddingRight="5dp" 
       android:textColor="@android:color/black"/> 

      <TextView 
       android:id="@+id/tvItemDetailsRemarks" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       tools:text="Remarks:" 
       android:textSize="18sp" 
       android:layout_gravity="center"/> 

     </LinearLayout> 

    </android.support.v7.widget.CardView> 

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

+0

爲什麼'NestedScrollView'在另一個'NestedScrollView'內? – pskink

+0

對不起,編輯了xml,在複製 –

+0

時發生了一些事情,所以現在你的'NestedScrollView'有多個子視圖? – pskink

回答

2

把LinearLayout中NestedScrollView後如下圖所示,如果你不想嘗試RecyclerView:

<android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

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

      <android.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 
      <android.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 

0

你有內部NestedScrollViewScrollViewNestedScrollView多個子視圖只能承載一個孩子。

要解決你的佈局,把所有的東西到任何一個ViewGroup如LinearLayout/RelativeLayout然後安排你的觀點。因此

0

你應該實現這樣的:

<android.support.v4.widget.NestedScrollView 
     android:id="@+id/activity_Recipe_detail_scrollview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 
       // do what ever you need here 
     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 

希望這個幫助

相關問題