2016-11-14 10 views
0

でビューの重複を避けるために、私は次のようなレイアウトの構造を有する:どのようにRelativeLayout

<RelativeLayout> 
    <ScrollView> 
     <LinearLayout> 
      <RelativeLayout> 
       <LinearLayout android:id="@+id/ContentNo1"> <-- Align top 
       </LinearLayout> 
       <LinearLayout android:id="@+id/ContentNo2"> <-- Align bottom 
       </LinearLayout> 
      </RelativeLayout> 
     </LinearLayout> 
    </ScrollView> 
    <Button/> <-- Always bottom of the page 
</RelativeLayout> 

マイボタンがFIRST RelativeLayoutにボトム整列され、そして私のScrollViewそれに上揃えを...

2番目のRelativeLayout内でContentNo1をTop-Alignし、ContentNo2をBone-Align ContentNo2にしたいと考えています。

私はこれを行いましたが、ContentNo1が大きすぎるとContentNo2が重なってしまいました。ダウン...それを行う方法?

...(この辺りでいくつかのトピックで説明するように)私は/ layout_aboveをlayout_below使用するように、試してみたが、私はそれを使用する場合、ContentNo2のボトムアライメントが却下される - EDITを -

Wasiには写真があり、ここで、尋ねたよう:(私は2つの以上のリンクを投稿することはできませんし、私はそれを説明するには、このページを作りました)

http://www.mydonorlife.hol.es/relativeissue/

- EDIT 2 - SOLUTION - これが私のために働いた

:私は2番目RelativeLayoutを取り出し、次のようないくつかのビュー>>

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:layout_alignParentTop="true" 
     android:fillViewport="true"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
                <!-- CONTENT NO 1 --> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:layout_marginBottom="30dp"> 
      </LinearLayout> 
                <!-- /CONTENT NO 1 --> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:orientation="vertical" 
       android:layout_weight="1" 
       android:layout_height="0dp"> 
                <!-- CONTENT NO 2 --> 
       <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="match_parent" 
        android:gravity="bottom" 
        android:layout_height="match_parent" 
        android:layout_weight="0"> 
       </LinearLayout> 
                <!-- /CONTENT NO 2 --> 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 
    <Button 
     android:layout_alignParentBottom="true"/> 
</RelativeLayout> 

がそれを願っています上のいくつかの重量/高さのトリックを設定しました後で誰かを助ける...

+0

あなたはそれをフルスクリーンにするために、外側のLinearLayoutにマッチ親を使用して、layout_belowを使用することができます/ layout_above。次に、ボトムアライメントは消えません。 layout_below/layout_aboveを使用すると、2つの相対レイアウトが重複しないようにすることができます。 –

+0

layout_below/aboveを使用すると、outer LinearLayoutは既にmatch_parentの高さで設定されており、bottom-alignmentは消えていきます。 –

+0

bottom-alignmentが消えることは、content2が画面の残りの部分にフィットしないことを意味しますか?あなたは写真を共有できますか?イメージはこの問題のより良い説明を与えるかもしれません! –

答えて

1

私はあなたのコードのいくつかを変更して、あなたが望むようにレイアウトを作ろうとしました。

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
     <ScrollView 
      android:id="@+id/scrollview" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_alignParentTop="true" 
      android:fillViewport="true"> 
      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 
       <!-- CONTENT NO 1 --> 
       <LinearLayout 
        android:id="@+id/linerlayout" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical" 
        android:layout_marginBottom="30dp"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Top aligned text1"/> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Top aligned text2"/> 
       </LinearLayout> 
       <!-- /CONTENT NO 1 --> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:orientation="vertical" 
        android:layout_below="@+id/linerlayout" 
        android:layout_height="wrap_content"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="bottom aligned text1"/> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="bottom aligned text2"/> 
        <!-- CONTENT NO 2 --> 
        <LinearLayout 
         android:orientation="vertical" 
         android:layout_width="match_parent" 
         android:gravity="bottom" 
         android:layout_height="match_parent" 
         android:layout_weight="0"> 
        </LinearLayout> 
        <!-- /CONTENT NO 2 --> 
       </LinearLayout> 
      </RelativeLayout> 
     </ScrollView> 
     <Button 
      android:layout_alignBottom="@id/scrollview" 
      android:text="bottom button" 
      android:layout_alignParentBottom="true" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      /> 
    </RelativeLayout> 

はまた、あなたの要件ごとにNO 1とCONTENTあなたCONTENT NO 2 UIを追加することができます

+0

でそれらを追加しました、それはまた本当にうまく動作します –

+0

@ T.Limaありがとう。 –

関連する問題