2017-05-17 5 views
0

私はレイアウト管理に苦労しているので、ここで質問しました。 3つのレイアウトを一定の方法で動作させたいと考えています。 私は3つのビューを、RelativeLayoutに垂直にディスパッチしました(VTop、VMiddle、VBottomと呼ぶ)。正確なアンドロイドレイアウトのサイズを試す

VBottomはボタンです。私は彼が画面の一番下に揃っていて、決して移動したりサイズを変更したりしないようにしたいと考えています。

VMiddleはスクロール表示です。私は、このScrollViewが下のボタン(VBottom)と一番上のレイアウト(VTop)の間のすべての可能な場所を取るようにしたいが、特定のサイズよりも劣っていることは決してない。

VMiddleがその最小サイズよりも小さくならない限り、すべてのコンテンツをラップするVTop(いくつかのTextViewsや他のものを含む線形レイアウト)が必要です。

実際にはコードはほとんど動作していますが、VMiddleにあまりにも多くのコンテンツを注入すると、画面の上部に向かって成長し続け、VTopは完全に消えます。 VTopにコンテンツをラップするのに十分なスペースがない場合、VMiddleを最小サイズに維持します。あなたの答えのための

Problem Schema

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/relativeLayout1"> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout1" <!-- VTop --> 
     android:layout_above="@+id/eventDetail_RateLayout" 
     android:layout_alignParentTop="true" 
     android:layout_margin="10sp"> <!-- LOT OF VIEWS, NEED TO BE WRAPPED AS MUCH AS POSSIBLE --> 
    </LinearLayout> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="100px" 
     android:id="@+id/eventDetail_RateLayout" <!-- Not visible for now, you can ignore it --> 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="10dp" 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:background="@color/common_google_signin_btn_text_light_default" 
     android:layout_above="@+id/eventDetail_CommentScrollView" 
     android:visibility="gone" /> 
    <ScrollView 
     android:id="@+id/eventDetail_CommentScrollView" <!-- VMiddle --> 
     android:background="#4D4A58" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/eventDetail_commentButton"> 
     <LinearLayout 
      android:orientation="vertical" 
      android:minWidth="25px" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/eventDetail_CommentLayout" /> 
    </ScrollView> 
    <Button 
     android:text="commenter" 
     android:id="@+id/eventDetail_commentButton" <!-- VMiddle, this one is doing ok --> 
     android:background="#666" 
     android:textColor="#f8f8f8" 
     android:layout_width="match_parent" 
     android:layout_height="30sp" 
     android:layout_alignParentBottom="true" /> 
</RelativeLayout> 

感謝。

+1

利用の重み.... – Zoe

答えて

0

最終的に私が望むものに近いものを得ることができました。私はlayout_aboveとそれ以下を組み合わせて、巨大なTextViewをスクロール可能にすることでVTopのサイズを固定しました。私は今VTopとVBottomを固定サイズにし、VMiddleを残りの部分を中心に持っています。あなたの速い答え:)

0

ScrollView次のコード試してみてください -

<ScrollView 
     android:id="@+id/eventDetail_CommentScrollView" <!-- VMiddle --> 
     android:background="#4D4A58" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_below="@id/linearLayout1" 
     android:layout_weight="1" 
     android:layout_above="@+id/eventDetail_commentButton"> 
... 
    </ScrollView> 
0

使用これは、しかし、あなたがしたいUIの種類を簡単にリニアレイアウトを使用し、重量とweightSumプロパティを使用して達成することができます..また、レイアウトのIDの名前を変更そして、ビューは、それに応じて

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

    <LinearLayout 
     android:id="@+id/topLayout" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:layout_alignParentTop="true" 
     android:background="#70AD47" 
     android:orientation="vertical"> 

    </LinearLayout> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/btnBottom" 
     android:layout_below="@+id/topLayout" 
     android:background="#ED7D31" 
     android:minHeight="400dp"> 

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

     </LinearLayout> 

    </ScrollView> 

    <Button 
     android:id="@+id/btnBottom" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:background="#4472C4" 
     android:text="Bottom button" /> 


</RelativeLayout> 
+0

ため

おかげで、私は最初のLinearLayoutを使用していたが、私は私が望んでいたように反応するビューを得ることができませんでした相対的な原因の一つにスワップ。しかし、weight_sumプロパティを使用しようとしなかったので、これをチェックします。 –

+0

@ Jasone.L確かに、私はそれが助けてくれることを願っています。 –

0

1.中間位置にそれを維持するためにScrollViewに属性android:layout_below="@id/linearLayout1"android:layout_above="@id/eventDetail_commentButton"を追加します。

2.使用ScrollViewとその子LinearLayoutその必要はないが、高さandroid:layout_width="match_parent"

topのレイアウトとbottomのレイアウトの大きさにかかわらず、scrollviewは常に中間の空きスペースを埋めるでしょう。 heighttopbottomのレイアウトに変更されることはありません。ここで

は作業レイアウトです:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/relativeLayout1"> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout1" 
     android:layout_alignParentTop="true" 
     android:layout_margin="10sp"> 

    </LinearLayout> 

    <Button 
     android:text="commenter" 
     android:id="@+id/eventDetail_commentButton" 
     android:background="#666" 
     android:textColor="#f8f8f8" 
     android:layout_width="match_parent" 
     android:layout_height="30sp" 
     android:layout_alignParentBottom="true" /> 

    <ScrollView 
     android:id="@+id/eventDetail_CommentScrollView" 
     android:background="#4D4A58" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/linearLayout1" 
     android:layout_above="@id/eventDetail_commentButton"> 

     <LinearLayout 
      android:orientation="vertical" 
      android:minWidth="25px" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/eventDetail_CommentLayout" /> 
    </ScrollView> 

</RelativeLayout> 

希望これは〜

+0

あなたの答えはちょっと、thx。私はすでに上記のレイアウトとベローズとあなたの正確な命題を組み合わせたすべてのトリックを試しました。しかし、この修正では、VTopは常にラップされますが、VMiddleに設定した最小サイズ(この場合、miniddleはVMiddleでは完全に無視されます)にかかわらず、VTopがあまりにも多くの場所を占めると、VMiddleが消滅します:/ –

+0

中間レイアウト。 – FAT

0

利用アンドロイド助ける:私はlayout_below = "@ + ID/linearlayout1" eventDetail_RateLayout

0

を与えられた答えのどれも、あなたが探しているものを達成することはありません。あなたがしたいのは単純なものではありません。なぜなら、循環的な依存関係が含まれているからです。つまり、vMiddleビュー(android:layout_above="@id/vMiddle")によって残されたスペースを折り返して埋めるようにしたいと同時に、vMiddleビューを囲み、 vTopビュー(android:layout_below="@id/vTop")によって残されました。 私が想像できる唯一の解決策は、プログラムでビューのサイズをチェックして設定することですが、これはレイアウトを並べ替えるだけでは実現できないと思います。

+0

ねえ、別のプロパティで操作の束を試した後、私はこの結論に行きました。私はプログラマティカルに行くつもりだと思うが、誰かがResizingイベントを上書きせずにそれを達成するためのトリックを持っている場合に備えてここに最初に投稿した。 –

関連する問題