2013-08-26 3 views
6

안녕하세요 저는 두 개의 버튼, 라디오 버튼 및 그래프보기가 포함 된 RelativeLayout을 만들었습니다.RelativeLayout을 두 개의 반쪽으로 나누기

그래프에 두 개의 다른 데이터를 표시하고 싶습니다.

어떻게 RelativeLayout을 두 개로 나눕니까?

이 내 존재하는 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

여기서 질문하지 못했습니다. 정확히하고 싶은게 뭐야? 화면에 두 개의 그래프를 추가 하시겠습니까? 둘 다 동일한 공간을 차지합니까? 또는 원하는 레이아웃을 보여주는 샘플 도면을 업로드 할 수 있습니다. – Sagar

+0

예 현재 레이아웃은 웨이브 폼의 ECG 신호를 보여주는 그래프 뷰가있는 상대적 레이아웃입니다. 나는이 그래프를 반으로 나누고 다른 반쪽에서 호흡의 신호를 보여주고 싶습니다. 같은 장소에 있어야 할 바닥에 3 개의 버튼이 있습니다. –

답변

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

감사합니다. 하지만 첫 번째 루블은 두 개의 그래프 뷰가 수직으로 비슷하지만 두 개의 스크린으로 나뉘어져있는 수평을 필요로한다는 것입니다. 또한 두 그래프는 정확히 서로 중복 된 복사본을 찾습니다. 첫 번째 그래프에는 값과 같은 것이 있지만 캔버스에 다른 것을 넣고 싶습니다. 예 : 캔버스에 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

즉각적인 답장을 보내 주셔서 감사합니다. @ 예 린 아웅 ....하지만 코드를 붙여 그래픽 레이아웃에서 볼 때. 나는 아무 변화도 보지 않는다. –

+0

죄송합니다. 나는 그 답을 바로 잡았다. –

+0

안녕하세요 덕분에 다음과 같은 오류가 발생했습니다 : 루트 요소 뒤에 오는 문서의 마크 업은 올바른 형식이어야합니다. –

14

따라서,이를 위해 가장 좋은 방법은 내가 다음, 레이아웃의 중앙에 정렬 크기가 0 인 전망을 가지고 (총 해킹 같은 느낌,하지만 매력처럼 작동하는)입니다 발견했습니다 해당 뷰의 왼쪽 절반을 정렬하고 해당 뷰의 오른쪽에 오른쪽 절반을 맞 춥니 다. 예를 들어 RelativeLayout.LinearLayout 당신이있는 LinearLayout의 layout_weight를 속성을 사용하여 원하는대로 수직 또는 수평으로 정확히이 개 부분에 화면을 분할 할 수 있습니다보다는

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

안녕하세요 덕분에 나는 이것을 시도했지만 다음과 같은 오류가 발생했습니다 : 오류 : 오류 : 문자열 형식이 허용되지 않습니다 ('anchor'값으로 'layout_toRightOf'에서). –

+1

수정 됨. ID를 잊어 버렸지 만 확인할 수 있어야하는 일반적인 ID입니다. – kcoppock

+0

그냥 내가 원하는 걸! :) –

5

사용의 LinearLayout.

layout_weight를 사용하면 여러보기 사이의 크기 비율을 지정할 수 있습니다. 예 : MapView와지도에 몇 가지 추가 정보가 표시되어야하는 표가 있습니다. 지도는 화면의 3/4을 사용해야하고 표는 화면의 1/4을 사용해야합니다. 그런 다음지도의 layout_weight를 3으로 설정하고 표의 layout_weight를 1로 설정합니다.

화면을 두 부분으로 나누는 코드를 작성하십시오. 코드 안드로이드에서

<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

관련 문제