2011-03-17 6 views
4

텍스트가 들어있는 텍스트 뷰 아래에 숫자로 텍스트 뷰를 배치하고 싶습니다. 나는이 레이아웃을 사용하고 textviews는 중복 : 어떻게 내가이 함께 얻을 것은상대 레이아웃의 다른 textView 아래에 textView 위치 지정 문제가 있습니다.

<?xml version="1.0" encoding="utf-8"?> 

    <LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:background="@drawable/back" 
xmlns:android="http://schemas.android.com/apk/res/android"> 

<!-- we include header --> 
<include 
    layout="@layout/header"/> 

<Spinner 
    android:id="@+id/spinner" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:layout_marginTop="15dip" 
    android:layout_marginLeft="5dip" 
    android:layout_marginRight="5dip" 
    android:textColor="#ffffff" 
    android:background="@drawable/spin" /> 

    <RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="#000000"> 

<TextView 
    android:id="@+id/tv1" 
    android:text="Some text to display:" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:layout_marginTop="10dip" 
    android:textColor="#ffffff" /> 

    <TextView 
    android:id="@+id/number" 
    android:text="123 456 789" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:textSize="30dip" 
    android:layout_marginTop="10dip" 
    android:textColor="#ffffcc"/> 

    </RelativeLayout> 

    </LinearLayout> 

: 당신이 android:layout_below="@id/tv1"을 필요로 두 번째 TextView

android:layout_below="@id/tv1"  

답변

18

를 추가

enter image description here

6

에 숫자 용 텍스트 뷰

4

상대 레이아웃을 사용하고 있지만 두 번째 TextView에 상대적인 위치를 알려주지 않습니다. 두 번째 텍스트 뷰에이 추가 :

android:layout_below:"@id/tv1" 
+1

안녕하세요, "@ + id"표기법을 사용하면 R.java 파일에 새로운 ID 문자열이 추가됩니다. TextView에 이미 ID가 있으면 "+"문자를 생략해야합니다. –

+2

참으로. 나는 이제 13 개월 편집을 수행 할 것입니다! – Blumer

+0

13 개월 후에도 코드는 여전히 나와 같은 사람들이 읽고 읽을 수 있습니다! :) –

0
RelativeLayouts가에 탑 디자인에 의해 서로의 요소를 스택에 의미되지 않는 한, 다음과 같은 코드가 다른 텍스트 뷰 아래에 텍스트 뷰를 생성하지 않는 한 당신은있는 LinearLayout을 사용한다

;

<LinearLayout 
     android:id="@id/deal_time_details" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/deal_item_bg_red_gradient" 
     android:baselineAligned="false" 
     android:gravity="center_horizontal" 
     android:orientation="vertical" 
     android:paddingBottom="6.0dip" 
     android:paddingLeft="10.0dip" 
     android:paddingRight="12.0dip" 
     android:paddingTop="6.0dip" > 

      <TextView 
       android:id="@id/name" 
       style="@style/deal_item_text" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center_horizontal" 
       android:text="@string/deal_details_time_ends" /> 

      <TextView 
       android:id="@id/company" 
       style="@style/deal_item_number" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="-1.0dip" 
       android:gravity="center_horizontal" 
       android:gravity="center_vertical" 
       android:text="@string/deal_details_time_redem" 
       android:textSize="12.0dip" /> 
    </LinearLayout> 
0

추가 : 아래 위치 할 뷰의 XML로

android:layout_below="@id/tv1" 

.