0

我有這個佈局文件的片段,不顯示最後一個textview元素,tv_notice_date,任何時候內容超過屏幕高度。我向cardview添加了一個滾動條,但滾動條不顯示。Cardview隱藏一些元素,滾動條不工作

fragment_notice.xml

<?xml version="1.0" encoding="utf-8"?> 
<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="wrap_content" 
    android:orientation="vertical"> 

    <android.support.v7.widget.CardView 
     android:id="@+id/card_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="vertical" 
     android:layout_margin="4dp" 
     card_view:cardCornerRadius="4dp" 
     card_view:cardElevation="1dp"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 
      <!--Title of notice--> 
      <TextView 
       android:id="@+id/tv_notice_title" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       android:text="Title of Notice" 
       android:layout_gravity="center" 
       android:textAppearance="?android:textAppearanceLarge" 
       android:textSize="20sp" 
       android:textStyle="bold"/> 

      <TextView 
       android:id="@+id/tv_notice_summary" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:padding="10dp" 
       android:text="@string/notice_body" 
       android:textAppearance="?android:textAppearanceMedium" 
       android:textSize="15sp"/> 
     <!--Date of Notice--> 
     <TextView 
      android:id="@+id/tv_notice_date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="5dp" 
      android:text="Mon, Nov 28, 2016. 8:56 AM" 
      android:textColor="#0D47A1"/> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 
</LinearLayout> 

的strings.xml

<string name="notice_body"> 
    Summary of the very first post...Summary of the very first post...Summary of the very first post... 
    Summary of the very first post...Summary of the very first post...Summary of the very first post... 
    Summary of the very first post...Summary of the very first post...Summary of the very first post... 
    Summary of the very first post...Summary of the very first post...Summary of the very first post... 
    Summary of the very first post...Summary of the very first post...Summary of the very first post... 
    Summary of the very first post...Summary of the very first post...Summary of the very first post... 
    Summary of the very first post...Summary of the very first post...Summary of the very first post... 
    Summary of the very first post...Summary of the very first post...Summary of the very first post... 
    Summary of the very first post...Summary of the very first post...Summary of the very first post... 
    Summary of the very first post...Summary of the very first post...Summary of the very first post... 
</string> 

我想顯示滾動條隨時隨地內容更使日期的TextView可以顯示。

回答

1

爲了有一個卡,你可以使用下面的結構外的滾動:

<ScrollView 
    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"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
      <!-- your content here --> 
     </LinearLayout> 
    </android.support.v7.widget.CardView> 
</ScrollView> 

你可以有一個卡內滾動,但在這種情況下,卡將始終佔據整個屏幕身高即使沒有太多的內容:

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

    <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"> 
      <!-- your content here --> 
     </LinearLayout> 
    </ScrollView> 
</android.support.v7.widget.CardView> 
+0

它的工作原理。但是,如果我可能會問,爲什麼cardview上的android:scrollbars屬性不顯示滾動條,但它爲recyclerviews。 –

0

我不知道,但如果這不是工作,然後你可以嘗試像

LinearLayout 
.... 
...> 
<ScrollView 
..... 
...> 
<CardView 
.... 
....> 
.... 
other views and Viewgroups 
.... 
</CardView 
</ScrollView> 
</LinearLayout> 

回來後你會得到什麼!讓我們知道

+0

它的工作原理!!!!!!! –