2011-03-13 5 views
0

하나의 텍스트보기가 끝나면 다른 텍스트보기가 이전의 왼쪽 가장자리에서 시작되도록 두 개의 텍스트보기를 그려야합니다. 나는 각각의 텍스트가 다를 수 있기 때문에 이것을 프로그램 적으로해야만한다. 첫 번째 텍스트 뷰의 왼쪽 가장자리의 x 좌표를 얻는 방법과 첫 번째 텍스트 뷰의 왼쪽 가장자리와 일치하도록 두 번째 텍스트 뷰의 오른쪽 가장자리를 설정하는 방법은 무엇입니까?다른 텍스트 뷰의 왼쪽 가장자리에 텍스트보기를 설정하는 방법은 무엇입니까?

도움을 주시면 감사하겠습니다.

편집 : 여기

<TextView android:gravity="center_vertical|left" 
    android:textColor="#000000" android:textSize="10dip" android:id="@+id/updateorder" 
    android:layout_marginTop="50dip" android:layout_alignParentRight="true" 
    android:text="x" style="@style/compactview" android:background="@drawable/ornage" 
    android:paddingLeft="5dip" android:layout_marginRight="73dip"></TextView> 
<TextView style="@style/compactview" android:id="@+id/neworder" 
    android:textColor="#000000" android:background="@drawable/red1" 
    android:layout_alignBottom="@id/updateorder" android:text="x" 
    android:textSize="10dip" android:gravity="center" 
    android:layout_toRightOf="@id/updateorder"></TextView> 

답변

0

RelativeLayout 문서와 layout_toLeftOf, layout_toRightOf 속성에 대한 나의 레이아웃입니다. 샘플 사용량은 tutorial에서 확인할 수 있습니다. 무엇보다 layout_widthlayout_heightwrap_content으로 설정하면 프로그래밍 방식으로 수행 할 필요가 없습니다.

+0

동적으로 매개 변수를 설정해야합니다. – user590849

1

이 프로그램을 수행 할 필요가 없습니다. Just Define 아래의 두 가지 레이아웃.

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

<TextView android:layout_height="wrap_content" android:text="TextView1" 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content"></TextView> 
<TextView android:layout_height="wrap_content" android:text="TextView2" 
    android:id="@+id/textView2" android:layout_width="wrap_content" 
    android:layout_toRightOf="@+id/textView1" 
    ></TextView> 

</RelativeLayout> 

당신은 코드뿐만 아니라 그러나 명확하게 볼 수에 대한 정확한 위치를 얻을 필요가 없습니다를 사용하여이 일을 달성 할 수있다.

+0

위 레이아웃을 사용했지만 두 번째 텍스트 상자가 첫 번째 텍스트 상자 옆에 정렬되지 않습니다. – user590849

+0

android : layout_alignParentRight = "true"이것은 화면 오른쪽의 첫 번째보기와 android : layout_toRightOf = "@ id/updateorder"보기를 벗어나는 오른쪽의 두 번째보기입니다. 첫 번째로 설정합니다. 부모를 오른쪽으로 정렬하지 않기 위해보기 – Javanator

+0

android : layout_alignParentLeft = "true"첫 번째보기에서 이것을 시도한 다음 요구 사항에 따라 변경하십시오 – Javanator

관련 문제