2017-08-16 91 views
0


我在選項卡內的ListView的大小有問題。
我認爲這很簡單,但我找不到解決方案。

活動與默認相同,除了用ListView更改的TextView。
我使用帶有三個項目(「P1」,「P2」,「P3」)的虛擬列表的ArrayAdapter。
所有尺寸都設置爲「match_parent」或「WRAP_CONTENT」

我得到的是這樣的:我只看到「P1」,而不是整個列表,用少許滾動條允許值之間滾動。
我想看到的是整個列表。

screenshot of my app

有人能幫助我嗎?

Tab中的Android ListView只顯示一行

主活動佈局

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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:id="@+id/main_content" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="it.danapps.mycommunity.ChooseTags"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="@dimen/appbar_padding_top" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways" 
     app:popupTheme="@style/AppTheme.PopupOverlay"> 

     <Spinner 
      android:id="@+id/spinner" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 
    </android.support.v7.widget.Toolbar> 

</android.support.design.widget.AppBarLayout> 

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/container_choose_tags" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 



片段

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="it.danapps.mycommunity.ChooseTags$PlaceholderFragment"> 


<ListView 
    android:id="@+id/chooseTagListView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    /> 



編輯
1.強制高度300dp我看到名單。但是,我怎樣才能自動執行到Android,適應屏幕?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="it.danapps.mycommunity.ChooseTags$PlaceholderFragment"> 


<ListView 
    android:id="@+id/chooseTagListView" 
    android:layout_width="match_parent" 
    android:layout_height="300dp" 
    /> 



ListView with 300dp height

+1

嘗試將ListView和NestedScrollView的android:layout_height更改爲match_parent。 –

+0

我試過了,但沒有改變什麼 – DanB

回答

0

如果TextViews被設置爲 「match_parent」 這將是您的問題。確保你的TextViews使用設定的高度或使用「wrap_content」。否則,你的TextView將嘗試填充它放置的scrollview的高度,這就是爲什麼你只看到第一個。

+0

是的,強制高度爲300dp我看到了列表。但是,我怎樣才能自動執行到Android,適應屏幕? – DanB

+0

不確定你的意思?如果您需要scrollview中的每個單元格都是屏幕的高度,則可以以編程方式將子params的佈局參數設置爲屏幕高度。如果您需要TextViews的高度符合其包含的文本的要求,則可以使用「wrap_content」 – Devsil

+0

我希望在屏幕上看到整個列表:查看屏幕可用性之前的所有元素(其餘部分將顯示使用滾動條)。試着更好地解釋我:在屏幕上我有空間來看看3個元素,但如果我使用「Match_parent」或「fill_content」,我只能看到一個;強制高度爲dp(例如300),我正確看到3個元素。更新這篇文章的屏幕截圖 – DanB