2017-02-15 60 views
0

我需要做一個佈局像這樣的畫面:如何在Android中製作LinearLayout設計?

enter image description here

在這裏有國家根據Spinner值的變化,以及1 EditText,我們必須把手機號碼。 EditText需要格式 - 。國家代碼是從API中獲取的,並且數字是由用戶提供的。但是,這應該只顯示爲一個EditText,而不是TextViewEditTextLinearLayout

我該如何做到這一點?

<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

PLZ再看一遍我再次上傳 – 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

ok讓我試試.. – 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循環
0

我想你只需一套API值後,首先編輯文本如果在編輯文本字段用戶點擊他可以繼續在國家代碼

+0

gud選項..我試試 – user7316606

相關問題