2017-03-28 10 views
0

私は自分のプロジェクトでListViewを使用していましたが、通常のリストビューが通常は割り当てられたスペースの上部に表示されるので、リストビューから呼び出されたボタンから開始する必要があります画面上に表示されます)、それが実行されると、私は取り除きたい不要な領域を残します。短いリストビューの最後にスペースを削除するにはどうすればいいですか?

私のリストビューは、表示のために1-4アイテムを保持し、スクロールすると2アイテムを保持すると仮定します。 したがって、リスト自体がいっぱいではない状況があります。

リストビューで私が探しているものを行うことは可能でしょうか?

視覚的な例: 私の現在のListViewは、次のようになります。

Item 1 
Item 2 
Item 3 
*Button that changes the visibillity of the list view* 

これは、次のとおりです。

Item 1 
Item 2 
Item 3 
*unwanted space* 
*Button that changes the visibillity of the list view* 

私は、リストが短いと判明した場合、私のリストビューには、次のようになりたいですXMLのリスト表示

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:layoutDirection="ltr" 
    tools:targetApi="11"> 

    <ListView 
     android:id="@+id/lv" 
     style="@style/Widget.AppCompat.ListView" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:layout_above="@+id/chooserBtn" 
     android:layout_alignEnd="@+id/chooserBtn" 
     android:layout_alignStart="@+id/chooserBtn" 
     android:footerDividersEnabled="false" 
     android:headerDividersEnabled="false" /> 
</RelativeLayout> 
+0

ボタンのコードは? –

+0

listview_itemのコードを表示します。おそらく最後の項目にも適用される上または下からのパディング/マージンを与えるでしょう。 –

答えて

0

うん...私はウェブに少数のより多くの時間を見て、最終的には実用的なソリューションを見つけました。

添加する必要がXMLでこれら3行:

android:footerDividersEnabled="false" 
android:stackFromBottom="true" 
android:headerDividersEnabled="false" 
0

"wrap_content"の高さを使用する必要がありますリストビューと親レイアウト。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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="wrap_content" 
    android:layoutDirection="ltr" 
    tools:targetApi="11"> 
    <ListView 
      android:id="@+id/lv" 
      style="@style/Widget.AppCompat.ListView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/chooserBtn" 
      android:layout_alignEnd="@+id/chooserBtn" 
      android:layout_alignStart="@+id/chooserBtn" 
      android:footerDividersEnabled="false" 
      android:headerDividersEnabled="false" /> 
<!-- or use button code here just make listview height as "wrap_content"--> 
</RelativeLayout> 

これが役に立ちます。

+0

私は、私が従わなければならないスペースが限られているので、コンテンツをラップするために自分の高さを変更することはできません。 – RandomName

+0

次に完全なコードをここに入れてください。 – Cool7

関連する問題