2014-06-13 11 views
1

나는 안드로이드 애플 리케이션에서 일하고있다. 여기에 나는 하나를 다른 것 아래에 정렬해야하는 2 TextView이 있습니다. (i.e "Artist Name" should be exact below the "Title of song")안드로이드에서 텍스트를 서로 아래에 정렬하는 방법은 무엇입니까?

누구든지 TextView을 하나씩 정렬하는 데 도움이 될 수 있습니까? 미리 감사드립니다.

다음은

<RelativeLayout xmlns: 
    android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/list_selector" 
    android:orientation="horizontal" 
    android:padding="5dip" > 

    <TableLayout 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_centerHorizontal="true" > 

    <!-- Left side Thumbnail image --> 
    <TableRow android:id="@+id/thumbnail" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="3dip" 
    android:layout_alignParentLeft="true" 
    android:background="@drawable/image_bg" 
    android:layout_marginRight="5dip"> 

<ImageView 
    android:id="@+id/list_image" 
    android:layout_width="50dip" 
    android:layout_height="50dip" 
    android:src="@drawable/doc"/> 



<!-- Title Of Song--> 
<TextView 
android:id="@+id/title" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignTop="@+id/thumbnail" 
android:layout_toRightOf="@+id/thumbnail" 
android:text="love you the" 
android:textColor="#040404" 
android:typeface="sans" 
android:textSize="15dip" 
android:textStyle="bold"/> 

<!-- Artist Name --> 
    <TextView 
    android:id="@+id/artist" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/title" 
    android:textColor="#343434" 
    android:textSize="10sp" 
    android:layout_marginTop="1dip" 
    android:layout_toRightOf="@+id/thumbnail" 
    android:text="Mary" /> 

    <!-- Rightend Duration --> 
    <TextView 
android:id="@+id/duration" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentRight="true" 
android:layout_alignTop="@id/title" 
android:gravity="right" 
android:text="7:45" 
android:layout_marginRight="5dip" 
android:textSize="10dip" 
android:textColor="#10bcc9" 
android:textStyle="bold"/> 

    <!-- Rightend Arrow --> 
    <ImageView android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:src="@drawable/arrows" 
android:layout_alignParentRight="true" 
android:layout_centerVertical="true"/> 
</TableRow> 
</TableLayout> 

    </RelativeLayout> 
+0

를 사용합니다. – Jay

+0

이것은 프로그램에서 링크를 확인하는 가장 좋은 예입니다. http://stackoverflow.com/questions/14000755/android-table-layout-alignment – Jay

+0

LinearLayout을 사용하거나 'android : layout_alignBottom = "@ + id/title"' –

답변

3

간단하게 배치 할 this를 사용하는 다른의 관련된 귀하의 항목의.

androidHacker은이 같은 다른 아래에 하나의 텍스트 뷰를 배치 할 수 있습니다, 권리 :

android:layout_below="@+id/your_another_text_view"

비슷한 레이아웃은 당신이 여기 찾고있는이 튜토리얼 here입니다. 중력 적절한 재산이며, 그것을 사용 :

+0

@ robi Kumar Tomar., 그 작동하지 않는다 : ( – user3607124

+0

@ user3607124 –

+0

아직도 텍스트가 동일합니다 (즉, 노래 제목 아래에 정렬되지 않음) – user3607124

2

이 같은 시도 내 코드입니다 ..

android:layout_below="@+id/your_another_text_view" 

UPDATE 그냥 특별히 그 텍스트 뷰에 대한 상대 레이아웃의 사용을 만들 필요가

. 그것을 시도하고 알려주세요.

+0

@ AndroidHacker, 작동하지 않음 – user3607124

1
<TextView 
android:id="@+id/title" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignTop="@+id/thumbnail" 
android:layout_toRightOf="@+id/thumbnail" 
android:text="love you the" 
android:textColor="#040404" 
android:typeface="sans" 
android:textSize="15dip" 
android:textStyle="bold"/> 

<!-- Artist Name --> 
    <TextView 
    android:id="@+id/artist" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/title" 
    android:textColor="#343434" 
android:layout_alignLeft="@+id/title"// This line is new 
    android:textSize="10sp" 
    android:layout_marginTop="1dip" 

    android:text="Mary" /> 
+0

@ Wasim Ahmed, didnt help :( – user3607124

+0

대답을 수락했습니다. 어떤 대답 : –

2
// try this way,hope this will help you to solve your problem. 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/list_selector" 
    android:orientation="horizontal" 
    android:padding="5dip" > 

    <TableLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_centerHorizontal="true" > 

     <!-- Left side Thumbnail image --> 
     <TableRow android:id="@+id/thumbnail" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="3dp" 
      android:background="@drawable/image_bg" 
      android:layout_marginRight="5dp"> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 
       <ImageView 
        android:id="@+id/list_image" 
        android:layout_width="50dp" 
        android:layout_height="50dp" 
        android:layout_alignParentLeft="true" 
        android:src="@drawable/ic_launcher"/> 


       <TextView 
        android:id="@+id/title" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_toRightOf="@id/list_image" 
        android:text="love you the" 
        android:textColor="#040404" 
        android:typeface="sans" 
        android:textSize="15sp" 
        android:textStyle="bold"/> 

       <!-- Artist Name --> 
       <TextView 
        android:id="@+id/artist" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/title" 
        android:layout_toRightOf="@id/list_image" 
        android:textColor="#343434" 
        android:textSize="12sp" 
        android:layout_marginTop="1dp" 
        android:text="Mary" /> 

       <TextView 
        android:id="@+id/duration" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_toRightOf="@id/title" 
        android:gravity="right" 
        android:text="7:45" 
        android:layout_marginRight="5dp" 
        android:textSize="12sp" 
        android:textColor="#10bcc9" 
        android:textStyle="bold"/> 

       <ImageView 
        android:id="@+id/arrow_image" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/ic_launcher" 
        android:layout_alignParentRight="true" 
        android:layout_toRightOf="@id/duration" 
        android:layout_centerVertical="true"/> 

      </RelativeLayout> 
     </TableRow> 
    </TableLayout> 
</RelativeLayout> 
+0

@ Haresh, 고맙습니다. :) 도움이 되셨습니다. – user3607124

+0

@ Haresh, 텍스트가 정렬되지만 전체 내용이 가운데 정렬됩니다. – user3607124

+0

TableLayout에서 android : layout_centerHorizontal = "true"를 제거하려고 시도했습니다. –

0

시도는 여기에 트릭은 안드로이드가 있다는 것입니다있는 LinearLayout을 사용하거나 재산 android:layout_alignBottom="@+id/title"

+0

@ Ramki Anba, 그래도 시도했지만 작동하지 않습니다. ( – user3607124

관련 문제