2016-09-12 7 views
-3

私はここで言及したこのソリューションを使用しようとしていた縦半分に私の画面を分割し、各半分に異なる色を行い、2つの相対レイアウトをアクティビティで半分に分割する方法は?

したい>

Android: 2 relative layout divided in half screen

が、それはしていません私のために働く。

これは私のレイアウトです:

<?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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:baselineAligned="false" 
    android:orientation="horizontal" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context=".activities.alignmentActivities.Add_New_Project_Activity" 
    tools:showIn="@layout/app_bar_add__new__project_"> 


     <RelativeLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:background="#f00000" 
      android:layout_weight="1"> 
     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="0dp" 
      android:background="#00b0f0" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
     </RelativeLayout> 

</LinearLayout> 

どのように私は、2つのレイアウトの所望の効果を達成することができ、それぞれが縦画面の半分を取る\私は、間違ったリンクに記載された例を何をやっていますか?

+0

変更 'アンドロイドとして、その値を変更します。layout_heightは=「wrap_content」' 'match_parent'へ – Marat

+0

画面を縦に分割しますか? –

+0

このリンクを参照してくださいhttp://stackoverflow.com/questions/4961355/percentage-width-in-a-relativelayout/32168421#32168421 –

答えて

0

を使用する必要があるよりも、垂直方向に画面を分割したい場合は、この使用してみてください可能性があります

<?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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="2" 
    android:orientation="horizontal" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 


    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:background="#f00000" 
     android:layout_weight="1"> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="0dp" 
     android:background="#00b0f0" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 
    </RelativeLayout> 

出力:

Screenview

-1

あなたがXML以下android:orientation="vertical"および子のレイアウトを使用しているandroid:layout_width="match_parent"

チェック、

<?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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:baselineAligned="false" 
    android:orientation="vertical" 
    android:weightSum="2" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="#f00000" > 
    </RelativeLayout > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="#00b0f0" > 
    </RelativeLayout > 
</LinearLayout > 
0

このコードは動作します追加した後、あなたのLinearLayout

android:weightSum="2" 

で次の属性を追加します。 WeightSum属性を使用すると、それはあなたが、それは3つの部分に分けることにしたいdivided.Ifになりたい等分の合計数を定義し、3

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

     <RelativeLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@color/red"> 
     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@color/white"> 
     </RelativeLayout> 
</LinearLayout> 

**Preview Image Link** 

    [1]: http://i.stack.imgur.com/6JKTP.png 
関連する問題