2011-12-22 4 views
3

layout을 작성해야하지만 완벽하지는 않습니다.레이아웃을 상대적 레이아웃으로 작성하십시오.

enter image description here

이 방법

enter image description here

나는이 RelativeLayout를 사용하여이에서만 만들 필요가 만드는 오전을 필요지고. 나는이 내 코드

<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="15dp"> 
     <TextView android:text="Title" android:textColor="#ffffff" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:textSize="18dp" android:padding="5dp" 
      android:background="@drawable/tab_cyan" android:id="@+id/title_add_txt"/> 
     <EditText android:hint="Address Title" android:layout_width="match_parent" android:layout_height="wrap_content" 
      android:id="@+id/address_title" android:layout_toRightOf="@id/title_add_txt"/> 
     <TextView android:text="Address" android:textColor="#ffffffff" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:textSize="18dp" android:padding="5dp" 
      android:background="@drawable/tab_cyan" android:layout_below="@id/title_add_txt" 
      android:id="@+id/address_txt"/> 
     <EditText android:hint="Address" android:layout_width="match_parent" android:layout_height="wrap_content" 
      android:id="@+id/address" android:layout_below="@id/address_title" android:layout_toRightOf="@id/address_txt"/> 
</RelativeLayout> 
+0

나는이 시나리오에 대한 TableLayout을 사용하지 않는 이유를 잘 모르겠습니다하지만 RelativeLayout의를 사용하는 경우, 안드로이드 중 하나와 함께 연주 해 봅니다 : paddingTop 또는 안드로이드 : paddingBottom에 대한 TextView ... – Ahmed

답변

0

layout_alignBaseline가 문제를 해결해야한다 - 동일한 라인의 뷰의 텍스트 기준선 정렬 :

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="15dp" > 

    <TextView 
     android:id="@+id/title_add_txt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#5500ff00" 
     android:padding="5dp" 
     android:text="Title" 
     android:textColor="#ffffff" 
     android:textSize="18dp" /> 

    <EditText 
     android:id="@+id/address_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/title_add_txt" 
     android:layout_alignBaseline="@id/title_add_txt" 
     android:hint="Address Title" /> 

    <TextView 
     android:id="@+id/address_txt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/title_add_txt" 
     android:layout_marginTop="10dp" 
     android:background="#5500ff00" 
     android:padding="5dp" 
     android:text="Address" 
     android:textColor="#ffffffff" 
     android:textSize="18dp" /> 

    <EditText 
     android:id="@+id/address" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/address_title" 
     android:layout_toRightOf="@id/address_txt" 
     android:layout_alignBaseline="@id/address_txt" 
     android:hint="Address" /> 
</RelativeLayout> 

가 나는 또한 TextViews 사이에 여백을 추가했습니다. EditTexts가 제대로 정렬되지 않도록 내가 당신의 배경 이미지가없는 - - 그것은처럼 보이는 TextViews가 동일한 폭이있는 경우이 문제가되지 않을 것입니다

Device screen

당신은 글고의 여백 재생할 수 있습니다 TextViews를 사용하여 이들 사이에 필요한 공간을 추가하십시오.

+0

완벽한 감사를드립니다 – Pratik

1

TextViewEditText는 같은 크기 당신없는 것입니다 하위 레이아웃

를 사용하지 않고 Linearlayout를 사용하여 서브 레이아웃을 만들 수 있어요 수 있지만이 가능합니다. 같은 크기로 만들 수 있다면 잘 정렬 될 것입니다.

귀하의 견해 크기를 알려 주시면 가장 저렴한 내기가 아마도 LinearLayouts과 붙어있을 것입니다.

1

나는 그것을 테스트,하지만 도움이 될 경우에 볼 수 아니에요 다음과 같이

<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="15dp"> 
    <TextView android:text="Title" android:textColor="#ffffff" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:textSize="18dp" android:padding="5dp" 
     android:background="@drawable/tab_cyan" android:id="@+id/title_add_txt"/> 
    <EditText android:hint="Address Title" android:layout_width="match_parent" android:layout_height="wrap_content" 
     android:id="@+id/address_title" android:layout_toRightOf="@id/title_add_txt"/> 
    <TextView android:text="Address" android:textColor="#ffffffff" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:textSize="18dp" android:padding="5dp" 
     android:background="@drawable/tab_cyan" android:layout_below="@id/address_title" 
     android:id="@+id/address_txt"/> 
    <EditText android:hint="Address" android:layout_width="match_parent" android:layout_height="wrap_content" 
     android:id="@+id/address" android:layout_alignTop="@id/address_txt" android:layout_alignLeft="@id/address_title"/> 
</RelativeLayout> 

내가 무슨 짓을했는지 것은 : (대신 title_add_txt 이하) address_title 아래 address_txt을 맞 춥니 다. 또한 address_txt의 상단과 address_title의 왼쪽에 정렬되도록 address의 정렬을 변경했습니다 (이 방법은 다른 방법으로도 해결 될 수 있음).

광고 나는 말했다 : 나는 그것을 검증 할 수 없지만 적어도 시도해 볼 수있다.

+0

결과가 가깝지만 결과는 textview가 편집 문구의 중심이 아니기 때문에 동일한 레벨을 의미합니다 – Pratik

-1

LinearLayout에 두 개의 관련 컨트롤 (레이블 및 해당 입력)을 래핑하고 TextViewsandroid:layout_centerVertical="true" 설정을 사용합니다. 이 같은

뭔가를해야만 ...

<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="15dp"> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

     <TextView android:text="Title" android:textColor="#ffffff" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:textSize="18dp" android:padding="5dp" 
      android:background="@drawable/tab_cyan" android:id="@+id/title_add_txt" 
      android:layout_centerVertical="true" /> 
     <EditText android:hint="Address Title" android:layout_width="match_parent" android:layout_height="wrap_content" 
      android:id="@+id/address_title" android:layout_toRightOf="@id/title_add_txt"/> 
    </LinearLayout> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 
     <TextView android:text="Address" android:textColor="#ffffffff" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:textSize="18dp" android:padding="5dp" 
      android:background="@drawable/tab_cyan" android:layout_below="@id/title_add_txt" 
      android:id="@+id/address_txt" 
      android:layout_centerVertical="true"/> 
     <EditText android:hint="Address" android:layout_width="match_parent" android:layout_height="wrap_content" 
      android:id="@+id/address" android:layout_below="@id/address_title" android:layout_toRightOf="@id/address_txt"/> 
    </LinearLayout> 
</RelativeLayout> 
+1

중첩 된 레이아웃은 플랫폼 작성자가 권장하지 않습니다. 계층이 깊을수록 응용 프로그램의 속도가 느립니다 실행됩니다.[레이아웃 계층 구조 최적화하기] (http://developer.android.com/training/improving-layouts/optimizing-layout.html)에는 계층 구조가 평탄한 속도 향상의 예가 포함되어 있습니다. –

관련 문제