2013-08-26 29 views
6

こんにちは私は2つのボタン、ラジオボタンとグラフビューを含むRelativeLayoutを作成しました。RelativeLayoutを2つの半分に分割する

グラフに2つの異なるデータを表示したいと思います。

どのようにRelativeLayoutを2つに分割するのですか?

これは私の現在のXMLコードです:

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

    <Button 
     android:id="@+id/BtnStart" 
     android:layout_width="100dip" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginTop="5dip" 
     android:text="SlaveEnable" /> 

    <Button 
     android:id="@+id/BtnStop" 
     android:layout_width="100dip" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginTop="5dip" 
     android:layout_toRightOf="@id/BtnStart" 
     android:text="SlaveDisable" /> 

    <RadioButton 
     android:id="@+id/BtnSaveFile" 
     android:layout_width="100dip" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_toRightOf="@id/BtnStop" 
     android:text="SaveFile" /> 

    <helog.diwesh.NugaBest.GraphView 
     android:id="@+id/gview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@id/BtnStart" 
     android:layout_alignParentRight="true" /> 

</RelativeLayout> 
+0

私はここで質問しませんでしたか?正確に何をしたいですか?あなたは画面に2つのグラフを追加したいのですか?どちらも同じスペースを占有していますか?または希望のレイアウトを示すサンプル図面をアップロードすることができます。 – Sagar

+0

はい私の現在のレイアウトは、ECG信号を波形表示したグラフビューを持つ相対レイアウトです。私は今このグラフを半分に分割し、残りの半分は呼吸の信号を示したいと思います。同じ場所にあるはずの底に3つのボタンがあります –

答えて

2

このレイアウトを試してください。完全ではない場合、これはいくつかの変更で動作するはずです。これにより、2つのグラフが追加されます。

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

    <Button 
     android:id="@+id/BtnStart" 
     android:layout_width="100dip" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginTop="5dip" 
     android:text="SlaveEnable" /> 

    <Button 
     android:id="@+id/BtnStop" 
     android:layout_width="100dip" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginTop="5dip" 
     android:layout_toRightOf="@id/BtnStart" 
     android:text="SlaveDisable" /> 

    <RadioButton 
     android:id="@+id/BtnSaveFile" 
     android:layout_width="100dip" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_toRightOf="@id/BtnStop" 
     android:text="SaveFile" /> 

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
      android:layout_above="@id/BtnStart" 
      android:layout_alignParentRight="true" 
     android:orientation="vertical" 
    android:weightSum="2" > 

    <helog.diwesh.NugaBest.GraphView 
       android:id="@+id/gview1" 
       android:layout_height="0dp" 
       android:layout_width="match_parent" 
     android:layout_weight="1" /> 

    <helog.diwesh.NugaBest.GraphView 
       android:id="@+id/gview2" 
       android:layout_height="0dp" 
       android:layout_width="match_parent" 
     android:layout_weight="1" /> 

</LinearLayout> 

</RelativeLayout> 
+0

ありがとうございます。しかし、最初のルーブルは、2つのグラフビューが垂直に似ていることですが、私は2つに分かれた水平の画面を必要とします。また、両方のグラフは、お互いに正確に重複したコピーを探しています。最初のグラフには値のようなものがありますが、私はキャンバスに他のものを置いています。例:キャンバス上にHRと温度で構成された私のグラフビュー。キャンバスに呼吸の詳細を貼りたい。 –

+0

@RahulSharma:希望のレイアウトの簡単なスケッチを描いてアップロードできますか?理解しやすくなります。 – Sagar

+0

私は@ sagarを知っていますが、残念ながら私は新しいスクリーンショットを貼り付けるには十分な評判ポイントがありません.......しかし、テキストで何かを表示しようとしましょう----------- ----------------------------------------------- graphview1:温度-------------------------------------------------- ------------- graphview2:呼吸---------------------------------- ---------------------------- 3 button –

0

これは動作するはずです。 layout_weightを使用してRelativeLayoutLinearLayoutで削除しました。その後、

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight=".50" > 

     <Button 
      android:id="@+id/BtnStart" 
      android:layout_width="100dip" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dip" 
      android:text="SlaveEnable" /> 

     <Button 
      android:id="@+id/BtnStop" 
      android:layout_width="100dip" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dip" 
      android:text="SlaveDisable" /> 

     <RadioButton 
      android:id="@+id/BtnSaveFile" 
      android:layout_width="100dip" 
      android:layout_height="wrap_content" 
      android:text="SaveFile" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight=".50" > 

     <helog.diwesh.NugaBest.GraphView 
      android:id="@+id/gview" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 

</LinearLayout> 
+0

すぐにお返事いただきありがとうございます。@ Ye Lin Aung ....しかし、あなたのコードを貼り付けて、グラフィカルなレイアウトで見てください。私は何の変化も見ない。 –

+0

申し訳ありません。私は答えを修正しました。 –

+0

こんにちは、ありがとう、私は次のエラーがあります:ルート要素に続く文書のマークアップは整形式でなければなりません。 –

14

ので、このために、(総ハックのように感じますが、魔法のように動作します)私が見つけた最良の方法は、レイアウトの中央に揃え、ゼロサイズのビューを持つことです、左半分をそのビューの左に揃え、右半分をそのビューの右に揃えます。たとえば:

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

    <View 
     android:id="@+id/anchor" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_centerInParent="true" /> 

    <Button 
     android:id="@+id/left_side" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@id/anchor" 
     android:layout_alignParentBottom="true" 
     android:layout_marginTop="5dip" 
     android:text="Left Side" /> 

    <Button 
     android:id="@+id/right_side" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/anchor" 
     android:layout_alignParentBottom="true" 
     android:layout_marginTop="5dip" 
     android:text="Right Side" /> 

</RelativeLayout> 
+0

こんにちは、私はこれを試してみましたが、それは私に次のエラーを与えました:エラー:エラー:String型は許可されません( 'layout_toRightOf'値 'アンカー')。 –

+1

固定。 IDを忘れてしまったのですが、チェックできるはずの共通IDです。 – kcoppock

+0

ちょうど私が欲しかった! :) –

5

利用のLinearLayoutはなくRelativeLayout.LinearLayoutはあなたのLinearLayoutのlayout_weightプロパティを使用して欲しいとあなたが垂直方向または水平方向の正確な2つの部分に画面を分割することができます。

layout_weightでは、複数のビューのサイズ比を指定できます。例えば。 MapViewとテーブルにいくつかの追加情報をマップに表示する必要があります。マップは画面の3/4を使用する必要があり、表は画面の1/4を使用する必要があります。次に、マップのlayout_weightを3に、表のlayout_weightを1に設定します。

画面を2つに分割するコードを以下のように記述します。コードアンドロイドで

<LinearLayout 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:weightSum="2" 
     android:orientation="vertical"> 
    <LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="match_parent" 
      android:layout_weight="1"> 
    </LinearLayout> 
    <LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="match_parent" 
      android:layout_weight="1"> 
    <LinearLayout> 

:オリエンテーションあなたが垂直方向を使用している場合、それは縦にその子をarrageし、あなたが水平方向を指定した場合、それは水平にその子を手配しますorienttationを指定しています。

+0

@kcoppockソリューションは、必要に応じてリストパフォーマンスを向上させます。 – CoDe

関連する問題