2016-12-18 9 views
0

私はAndroidが初めてで、レイアウトに関して多くの問題に直面しています。私は上部にToolbarの画面を持っています。その下には、私はImageView、そしてImageViewの下には、ListViewがあります。私はListViewの高さをレイアウトする問題に直面しています。私のListViewは画面上の最後の項目なので、画面の残りの部分に合わせたいと思います。これは、適合するようにListViewのサイズを動的に変更したいのですか?以下は、私は、画面に設定されたレイアウトは次のとおりです。Androidの下部にリストビューを合わせるには

<?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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.team.sidhesh.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="617dp" 
     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/colorAccent" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

     <ImageView 
      android:id="@+id/sliderTempImageView" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/slider_image_height" 
      android:src="@drawable/slider_image1" 
      android:scaleType="centerCrop"/> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/slider_seperator_height" 
      android:src="@drawable/slider_seperator" 
      android:scaleType="fitXY"/> 

     <ListView 
      android:id="@+id/list_view" 
      android:background="@android:color/white" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentBottom="true"> 

     </ListView> 

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

答えて

0

あなたは、単に高さmatch_parentLinearLayout中にあなたListViewを囲み、bottomgravityを設定することができます。このようなもの、

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

    <ListView 
     android:id="@+id/list_view" 
     android:background="@android:color/white" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</LinearLayout> 
1

ビューの親ViewGroupのタイプによって異なります。

RelativeLayoutの両親については、Jeetendra Choudharyの答えはandroid:layout_alignParentBottom="true"で問題ありません。

LinearLayoutの親の場合は、ビューをレイアウトの最後の子にし、android:layout_weight="1"にスペースを埋め込んで下に配置する必要があります。

FrameLayoutの親の場合は、ビューにandroid:layout_gravity="bottom"を設定する必要があります。

ルートViewGroupとしてAppBarLayoutを使用しないでください。私はLinearLayoutまたはFrameLayoutをルートViewGroupとしてこのようなものをお勧めします。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     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/colorAccent" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

     <ImageView 
      android:id="@+id/sliderTempImageView" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/slider_image_height" 
      android:src="@drawable/slider_image1" 
      android:scaleType="centerCrop"/> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/slider_seperator_height" 
      android:src="@drawable/slider_seperator" 
      android:scaleType="fitXY"/> 

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

    <ListView 
     android:id="@+id/list_view" 
     android:background="@android:color/white" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</LinearLayout> 

さらに、ListViewはかなり時代遅れです。代わりにサポートライブラリからRecyclerViewを使用することをお勧めします。 https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html

関連する問題