2017-01-20 3 views
1

私は、4つのEditTextを並べて配置して、ボックス間にピリオド(3つのプレーンテキストビュー、それぞれ1つのピリオドを含む)を作成しようとしています。 4つのボックスは、IPアドレス入力に使用されます。レイアウトに配置したいのですが、RelativeLayoutまたはLinearLayout(水平)のいずれかを使用して、それらを適切に配置することはできません。ここでは、レイアウトファイルのコードは次のとおりです。4つのEditTextをそれぞれの間にピリオドを並べて並べる方法は?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:background="@color/colorDartGray" 
       android:paddingBottom="@dimen/activity_vertical_margin" 
       android:paddingLeft="@dimen/activity_horizontal_margin" 
       android:paddingRight="@dimen/activity_horizontal_margin" 
       android:paddingTop="@dimen/activity_vertical_margin" 
       tools:context="morega.mota.ui.SetIpAddressActivity"> 
    <!-- 
    <ProgressBar 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     style="?android:attr/progressBarStyleLarge" 
     android:id="@+id/ipaddress_loading" 
     android:progressDrawable="@drawable/circular_progress_bar" 
     android:layout_centerInParent="true"/> 
     --> 



    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/searching_button_view" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" > 
     <Button 
      android:layout_width="200dp" 
      android:layout_height="75dp" 
      android:text="@string/cancel" 
      android:id="@+id/cancel_button" 
      android:layout_marginLeft="10dp" 
      android:layout_marginStart="10dp" 
      android:layout_toRightOf="@+id/connect_button" 
      android:layout_toEndOf="@+id/connect_button"/> 
     <Button 
      android:layout_width="200dp" 
      android:layout_height="75dp" 
      android:id="@+id/connect_button" 
      android:text="@string/connect"/> 
    </RelativeLayout> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/company_logo" 
     android:src="@drawable/logo" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="@string/ip_address_instruction" 
     android:id="@+id/textView" 
     android:layout_below="@+id/company_logo" 
     android:layout_centerHorizontal="true" 
     android:textColor="#ffffff" 
     android:textSize="40sp"/> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="750dp" 
     android:layout_height="400dp" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true"> 

     <EditText android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1"/> 
     <TextView android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="."/> 
     <EditText android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1"/> 
     <TextView android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="."/>/> 
     <EditText android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1"/> 
     <TextView android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="."/>/> 
     <EditText android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1"/> 

    </LinearLayout> 


</RelativeLayout> 

私はそれがまた途中でセンタリングので、プログレスバーをコメントアウトしましたし、私は[デザイン]タブを使用して、ドラッグ&ドロップを使用して変更をしようとした際に干渉しましたAndroidスタジオ

+0

あなたのコードは、4つの 'EditText'や3つの' TextView'を表示しません。 – iRuth

答えて

0

このような何かは、あなたが一緒に実際のIPをつなぎする必要がありますが、それはあなたのフラグメント/活動にあまりにも難しいことではありません望ましい効果

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true"> 

    <EditText 
     android:id="@+id/ip_seg_1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:inputType="number" 
     android:maxLength="3"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="."/> 

    <EditText 
     android:id="@+id/ip_seg_2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:inputType="number" 
     android:maxLength="3"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="."/> 

    <EditText 
     android:id="@+id/ip_seg_3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:inputType="number" 
     android:maxLength="3"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="."/> 

    <EditText 
     android:id="@+id/ip_seg_4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:inputType="number" 
     android:maxLength="3"/> 

</LinearLayout> 

を実現します。

0

RelativeLayoutこれら4つのテキストビューを間隔をあけて並べて設定することができます。ボタンandroid:layout_toRightOfのためにすでに設定したのと同じ属性を使用し、作成する新しいテキストビューごとにIDを設定します。

<EditText 
    android:id="@+id/first" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
<TextView 
    android:id="@+id/second" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/first" /> 
<EditText 
    android:id="@+id/third" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="," 
    android:layout_below="@id/name" 
    android:layout_toRightOf="@id/second" /> 

relevant

0
Just place following Linear layout in your Relative layout it will display 4 edit text separated by period, you can further customise this code to exactly match your need 

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:gravity="center" 
     android:orientation="horizontal"> 

     <EditText android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:text="1234"/> 
     <TextView android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 

        android:text="." 
        android:textSize="30dp"/> 
     <EditText android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:text="1234"/> 
     <TextView android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 

        android:text="." 
        android:textSize="30dp"/> 
     <EditText android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:text="1234"/> 
     <TextView android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 

        android:text="." 
        android:textSize="30dp"/> 
     <EditText android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:text="1234"/> 


    </LinearLayout> 
+0

LinearLayoutに必要な背景色を与えて、適切な外観と感じを得る – 44kksharma

関連する問題