How to make LinearLayout design in Android?


I need to make a layout like this in picture:

<a href="https://i.stack.imgur.com/Rqr7U.jpg" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/Rqr7U.jpg" data-original="https://i.stack.imgur.com/Rqr7U.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Here there is country which changes according to Spinner value , and 1 EditText where we have to put mobile number. The EditText needs to have the format -. The country code is fetched from an API and the number is fed by the user. But, this should appear as one EditText only, not as a TextView and an EditText in a LinearLayout.

How can I achieve this?

<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>


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>


There are a couple of ways that you can achieve this,

<ol><li>Create a LinearLayout that has the background that you're putting in the Spinner and other EditTexts. Give it <em>horizontal</em> orientation and add a TextView (to contain the country code from your API) and an EditText that the user can enter his number in (preferably with weight = 1, and no background). This would achieve the same in an easy way.</li> <li>Create a String called countryCode in code, store the country code from the API in this. Add a TextWatcher to your EditText and prefix countryCode to the input. <strong>Note: changing text of a field within an onTextChanged() callback is not recommended as you may trigger an infi-loop</strong>.</li> </ol>


i think you simply set api value to edit text first after that if user click on the Edit Text field he can continue type his mobile number after the country code


  • Android - Horizontal progress bar with dots
  • How to keep Android Layout consistent across various devices?
  • Google map v2 Black Screen with Sherlock and ListView
  • Android - CardView background always grey
  • How close toolbar Espresso
  • Android Form with EditText makes the screen flash
  • Android WXGA emulator gets distortion in portrait orientation
  • Dimmed Background of PopupWindow excludes Toolbars / Action Bars
  • android spinner -onItemSelected
  • Make a normal layout look like a PreferenceScreen
  • Android layout , does it support orientation layout xml files? Does -land work at all?
  • How to dynamically setting relative layout background images?
  • Android XML Layout works in landscape but not in normal orientation
  • Creating custom view from xml
  • Glide is loading half image
  • Swipable Linear/Relative Layout
  • Flash screen Android
  • Why Android Studio creates two xml layout files
  • assigning dataframe to Panel in Pandas
  • How do I make an EditText raise along with the keyboard when in focus?
  • View disappears after setting height of gridLayout to wrap_content
  • onMeasure() called with EXACTLY and spec size 0
  • I can't show LinearLayout at bottom to scroll view
  • Can I override some attribute of drawable shape?
  • Sticky Footer Below ListView in Android Layout
  • Overlapping ImageView in RelativeView
  • Android How to disabled predictive text programatically in samsung tab 2
  • Float Label hint (TextInputLayout) not works with Android Data Binding
  • EditText ignores the ImeActionLabel
  • Build an array of ids of all select boxes
  • changes in jquery 1.4.2 breaking the code?
  • Gray line inside cardview :)?
  • Animate LayoutChanges does not work properly
  • jquery code not working without breakpoint
  • SAVE attribute needed for Fortran variables when only the C_LOC address is returned to a C program?
  • saving file generated by TCPDF
  • How Lists (specifically, RecyclerView with CardViews) in Android work
  • d3 v4 drag and drop with TypeScript
  • Android fill_parent issue
  • How to set my toolbar fixed while scrolling android