2

現在、私はLinearLayoutを子として他にもたくさんあります。それらのほとんどすべてはwrap_contentの高さを使用し、LinearLayoutのメインはwrap_contentを使用します。ただし、メインの末尾の子LinearLayoutRelativeLayoutで、match_parentを使用しています。これにはMapViewといくつかのボタンが含まれています。LinearLayout ScrollView:必要に応じて最後の子にminHeightを設定し、空白を埋める

enter image description here

私は最後の子の前にいくつかのより多くの子供たちを追加したいです。これを行うことで、マップが占めるスペースは、追加する子供が多くなるほど小さくなります。 wrap_contentであっても、他の子供たちが全体のスペースを占めているので、マップはもはや見えなくなります。

私の考えは、LinearLayoutScrollViewの内側に置くことです。それから私は無制限の子供を持つことができました。

私の質問はです:画面に十分なスペースがない場合でも表示できるように、RelativeLayoutを画面の残りの部分、または少なくとも200dpの高さにするにはどうすればよいですか最初に表示しますか?

enter image description here

私のレイアウトは/次のようになりならないかもしれません:

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

     <LinearLayout android:layout_height="wrap_content" ... > 

     <LinearLayout android:layout_height="wrap_content" ... > 

     <LinearLayout android:layout_height="wrap_content" ... > 

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

      <com.google.android.gms.maps.MapView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 

      <Button ... /> 
      <Button ... /> 
      <Button ... /> 
     </RelativeLayout> 
    </LinearLayout> 
</ScrollView> 

答えて

2

これを使用して、あなたはあなたがあなたのRealtiveLayoutの時にあなたの子供くらい、その後も空きスペース、 とDPをカバーしたい以下の子供を持っているときに ので重量を使用する必要があり、両方のDPと重量を使用する必要がありますあなたのRelativeLayoutのサイズを維持したい

<ScrollView 
     android:layout_width="match_parent" 
     android:fillViewport="true" 
     android:layout_height="match_parent" > 

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

      <LinearLayout android:layout_height="wrap_content" ... > 

      <LinearLayout android:layout_height="wrap_content" ... > 

      <LinearLayout android:layout_height="wrap_content" ... > 

      <!--Use dp also, because when you have more childs, 
       it wants a dp to maitain a size--> 
      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="200dp" 
       android:layout_weight="1"> 

       <com.google.android.gms.maps.MapView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" /> 

       <Button ... /> 
       <Button ... /> 
       <Button ... /> 
      </RelativeLayout> 
     </LinearLayout> 
    </ScrollView> 
+0

ありがとう、それは私が探していたものです。 MapViewでminHeight = "220dp"を設定し、RelativeLayoutをlayout_height = match_parentにし、RelativeLayoutをwrap_contentを使用する別のLinearLayoutに配置することで、同様の結果が得られました。あなたの解決策はクリアですが、私にheight = 0dpを使用するよう警告します(これは明らかにうまくいかないでしょう)。 残っている唯一の質問は、利用可能なスペースがある場合にweight = 1が200dpの高さを上書きし、スペースがない場合は無視する理由を説明する良いリソースがありますか?なぜminHeightの代わりにlayout_heightを使用するのですか? – xxtesaxx

+0

私はLinearLayoutではなくRecyclerViewを使っているところに非常によく似た質問があります。多分あなたはこの問題の解決法も知っていますか? http://stackoverflow.com/questions/41253811/make-last-item-viewholder-in-recyclerview-fill-rest-of-the-screen-or-have-a-mi – xxtesaxx

0

は、それはあなたを助けるコードの下に試してみてください。

<ScrollView 
     android:layout_width="match_parent" 
     **android:fillViewport="true"** 
     android:layout_height="match_parent" > 

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

      <LinearLayout android:layout_height="wrap_content" ... > 

      <LinearLayout android:layout_height="wrap_content" ... > 

      <LinearLayout android:layout_height="wrap_content" ... > 

      <RelativeLayout 
       android:layout_width="match_parent" 
       **android:layout_height="0dp" 
       android:layout_weight="1"**> 

       <com.google.android.gms.maps.MapView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" /> 

       <Button ... /> 
       <Button ... /> 
       <Button ... /> 
      </RelativeLayout> 
     </LinearLayout> 
    </ScrollView> 
+0

これはどのように最小の高さを考慮に入れますか? – xxtesaxx

+1

私は自分のコードをチェックインしました。それを試してみてください。 –

関連する問題