2011-12-22 22 views
3

このようにlayoutを作成する必要がありますが、完全にはできません。相対レイアウトでレイアウトを作成

この

enter image description here

を取得、私はRelativeLayoutを使用して、これを作成し、これだけで作成する必要があるのです

enter image description here

この方法が必要です。私はそれはあなたのTextViewEditTextが同じサイズでないようで、これは私のコード

<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を使用する必要がある場合は、Androidのどちらかで遊んでみてください: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

あなたがのEditTextのマージンで遊ぶことができますTextViewsを使用してそれらの間に必要なスペースを追加します。

+0

完璧な感謝を得て – Pratik

1

ある任意のサブレイアウトに

を使用せずに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の左にアライメントするように変更しました(これはおそらく他の方法でも解決されるかもしれません)。

私は言った:私はそれを確認することはできませんが、少なくともそれを試すことができます。

+0

結果が近くに届いていますが、その作業はtextviewが上にあるedittextの中心ではありません同じレベルを意味します – Pratik

-1

LinearLayoutに2つの関連するコントロール(ラベルと対応する入力)をラップし、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)には、フラット化された階層を持つ重要な高速化の例が含まれています。 –

関連する問題