2017-02-15 22 views
0

мне нужно сделать макет, как это в картинке:Как сделать дизайн LinearLayout в Android?

enter image description here

Здесь есть страна, которая меняется в зависимости от Spinner значения и 1 EditText, где мы должны поставить номер мобильного телефона. EditText должен иметь формат -. Код страны извлекается из API, а номер загружается пользователем. Но это должно выглядеть только как EditText, а не как TextView и EditText в LinearLayout.

Как я могу это достичь?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:fb="http://schemas.android.com/apk/res-auto" 
    android:background="@drawable/common_bg" 
    android:gravity="center_horizontal" 
    android:orientation="vertical" 
    tools:context="com.pigeonmarket.PMRegisterActivity"> 

    <!-- Login progress --> 
    <ProgressBar 


     android:id="@+id/login_progress" 
     style="?android:attr/progressBarStyleLarge" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="8dp" 
     android:visibility="gone" /> 


    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <RelativeLayout 
      android:id="@+id/registerform" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="center_horizontal" 
      android:layout_marginTop="20dp"> 

      <TextView 
       android:id="@+id/textView4" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@+id/toolbar_new" 
       android:layout_centerHorizontal="true" 
       android:text="REGISTER" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="#fff" 
       android:textSize="18dp" /> 

      <ImageView 
       android:id="@+id/imageView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 

       android:layout_centerHorizontal="true" 
       android:layout_marginTop="40dp" 
       android:background="@drawable/signup_icon" /> 



      <EditText 
       android:id="@+id/sname" 
       android:layout_width="match_parent" 
       android:layout_height="60dp" 

       android:layout_marginTop="14dp" 

       android:hint="Name" 
       android:paddingLeft="15dp" 
       android:textSize="14dp" 
       android:layout_below="@+id/imageView" 
       android:layout_centerHorizontal="true" /> 

      <Spinner 
       android:layout_width="match_parent" 
       android:layout_height="60dp" 
       style="?android:attr/spinnerItemStyle" 
       android:id="@+id/fbcountry" 

       android:paddingLeft="15dp" 
       android:layout_marginTop="12dp" 
       android:drawableRight="@drawable/down_arrow" 
       android:drawablePadding="15dp" 
       android:paddingRight="15dp" 
       android:spinnerMode="dialog" 
       android:layout_below="@+id/sname" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" /> 





      <TextView 

      android:layout_width="wrap_content" 
      android:layout_height="60dp" 
      android:paddingLeft="35dp" 
      android:layout_below="@+id/fbcountry" 
      android:layout_alignR="@+id/fbcountry" 
      android:hint="+" 
      android:layout_marginTop="30dp" 
      android:textSize="14dp"/> 


      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="60dp" 
       android:paddingLeft="50dp" 
       android:layout_below="@+id/fbcountry" 
       android:layout_alignR="@+id/fbcountry" 
       android:hint="code" 
       android:layout_marginTop="30dp" 
       android:textSize="14dp" 
       android:id="@+id/calling_code" /> 

      <EditText 
       android:layout_width="wrap_content" 
       android:layout_height="60dp" 
       android:paddingLeft="90dp" 
       android:layout_below="@+id/fbcountry" 
       android:layout_alignR="@+id/fbcountry" 
       android:hint="Mobile Number" 
       android:layout_marginTop="10dp" 
       android:textSize="14dp" 
       android:id="@+id/mob" /> 





     </RelativeLayout> 

    </ScrollView> 

</LinearLayout> 
+0

где картина? – user3040153

+0

нормально ждать я загрузить снова – user7316606

+0

плз увидеть снова я снова загрузил – user7316606

ответ

0
create background.xml in drawable & add this as background of edit text & spinner 

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid android:color="#00000000"/> <-- transparent--> 
    <stroke android:color="@color/grey" <-- grey color--> 
     android:width="10dp"/> 
    <corners 
     android:bottomLeftRadius="30dp" 
     android:bottomRightRadius="30dp" 
     android:topLeftRadius="30dp" 
     android:topRightRadius="30dp"/> 
</shape> 
+0

нормально, дайте мне попробовать .. – user7316606

+0

но ширина высота редактировать текст не как равный, как блесны – user7316606

+0

этот код будет создавать только фон вы должны дать ширину в макете XML – user3040153

0

Есть несколько способов, которые вы можете достичь этого,

  1. Создать LinearLayout, который имеет фон, который вы кладете в Spinner и других EditText с. Дайте горизонтальной ориентации и добавьте TextView (чтобы указать код страны из вашего API) и EditText, чтобы пользователь мог ввести свой номер (желательно с weight = 1 и без фона). Это обеспечило бы то же самое простым способом.
  2. Создайте String под кодом countryCode в коде, сохраните код страны из API в этом. Добавьте TextWatcher в ваш EditText и префикс countryCode на вход. Примечание: изменение текста поля в обратном вызове onTextChanged() не рекомендуется, так как вы можете вызвать infi-loop.
0

я думаю, что вы просто установите значение апи на первом редактировать текст после этого, если пользователь нажмет на текстовом поле Edit он может продолжать вводить свой номер мобильного телефона после того, как код страны

+0

гуд вариант .. мне попробовать – user7316606