I have two EditText fields in my Activity. I set the textSize to "20dp" in both. However, one EditText shows the hint text with larger spacing in letters than another.
How do I solve this issue?
here is my XML code with the activity screen preview.
mainActivity.xml
<RelativeLayout 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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#3B5998"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/login"
android:background="#drawable/round_button"
android:height="90dp"
android:text="Login"
android:textColor="#FFFFFF"
android:textSize="20dp"
android:layout_marginTop="41dp"
android:layout_below="#+id/password"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="fill_parent"
android:layout_height="40dp"
android:id="#+id/username"
android:layout_centerHorizontal="true"
android:background="#drawable/shape"
android:hint="Enter your username"
android:paddingLeft="5dp"
android:shadowRadius="5"
android:layout_marginTop="150dp"
android:textSize="20dp"
android:layout_marginBottom="0dp"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="40dp"
android:id="#+id/password"
android:background="#drawable/shape"
android:hint="Enter your password"
android:paddingLeft="5dp"
android:shadowRadius="5"
android:textSize="20dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp"
android:layout_below="#id/username"
android:inputType="textPassword"
/>
<TextView
android:layout_width="250dp"
android:layout_height="70dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="NxtStepz"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp"
android:gravity="center"
android:textSize="50dp"
android:textColor="#FFFFFF"
android:textStyle="italic|bold"
/>
Here is the link for the screenshot
You should never use the dp with text sizes. Always use sp. Try to replace your current EditTexts with those
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/username"
android:layout_centerHorizontal="true"
android:background="#drawable/shape"
android:hint="Enter your username"
android:paddingLeft="5dp"
android:shadowRadius="5"
android:textSize="20sp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:inputType="textPassword"
android:layout_marginTop="150dp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/password"
android:layout_centerHorizontal="true"
android:background="#drawable/shape"
android:hint="Enter your password"
android:paddingLeft="5dp"
android:shadowRadius="5"
android:textSize="20sp"
android:layout_marginTop="20dp"
android:layout_below="#id/username"
android:inputType="textPassword"
/>
Related
I have developed an android app that works fine, but the problem is that when I run my application on small screen phones then some components goes out of screen. So please tell what should I do with my app so that it fits on every screen?
Should I create all of these folders (given below) and copy-paste all of my app's layout files in each of these folders? Or I need to design different layout files for each of these folders?
I am new to android, please help by giving a simple example.
Folders:
res/layout/my_layout.xml
res/layout-small/my_layout.xml
res/layout-large/my_layout.xml
res/layout-xlarge/my_layout.xml
res/layout-xlarge-land/my_layout.xml
res/drawable-mdpi/my_icon.png
res/drawable-hdpi/my_icon.png
res/drawable-xhdpi/my_icon.png
XML of MainActivity of My Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
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="com.example.appdeveloper.appname.MainActivity"
android:background="#ff003b"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/appLogoImage_id"
android:src="#drawable/applogo"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="1000dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="50dp"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/loginPassword_id"
android:textAlignment="center"
android:hint="Enter Application Password"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:layout_below="#+id/appLogoImage_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="50dp"
android:background="#android:color/transparent"
android:visibility="visible"
android:textCursorDrawable="#drawable/white_cursor" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="REGISTRATION"
android:id="#+id/regTitle_id"
android:layout_below="#+id/appLogoImage_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#ffffff"
android:textAlignment="center"
android:layout_marginTop="50dp"
android:visibility="invisible"
android:textStyle="bold" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions|text"
android:ems="10"
android:id="#+id/regName_id"
android:layout_below="#+id/loginPassword_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Your Good Name"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_marginTop="0dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regPassword_id"
android:layout_below="#+id/regName_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Application Password"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regVerifyPass_id"
android:layout_below="#+id/regPassword_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Verify Password"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regRingCode_id"
android:hint="Ringing Codeword"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regVerifyPass_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regLocationCode_id"
android:hint="Location Codeword"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/regRingCode_id"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/regNum1_id"
android:hint="1st Trusted Number"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regLocationCode_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:phoneNumber="false" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/regNum2_id"
android:hint="2nd Trusted Number"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regNum1_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:phoneNumber="false" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/regNum3_id"
android:hint="3rd Trusted Number"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regNum2_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:phoneNumber="false" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:id="#+id/regButton_id"
android:layout_below="#+id/regNum3_id"
android:layout_marginTop="15dp"
android:layout_alignLeft="#+id/appLogoImage_id"
android:layout_alignStart="#+id/appLogoImage_id"
android:layout_alignRight="#+id/appLogoImage_id"
android:layout_alignEnd="#+id/appLogoImage_id"
android:visibility="invisible" />
</RelativeLayout>
Unless you soft code your dimensions (margin, padding, textsize) in dimen.xml file, your app will have different layout in phones having different ppi (pixel per inch).
So add all your margins specially the one having 1000dp in Dimens.xml.
Reason: Android handles all the cases (hdpi,mdpi,xhdpi, ....) on its own by going through dimens.xml file and in your case you are focusing on the preview screen in XMl layout editor that is having a fixed ppi and ignoring the cases of other screens having different ppi.
Your layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
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="com.example.appdeveloper.appname.MainActivity"
android:background="#ff003b"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/appLogoImage_id"
android:src="#drawable/applogo"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/margin_0" />
<EditText
android:layout_width="wrap_content"
android:layout_height="#dimen/margin_50"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/loginPassword_id"
android:textAlignment="center"
android:hint="Enter Application Password"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:layout_below="#+id/appLogoImage_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="#dimen/margin_50"
android:background="#android:color/transparent"
android:visibility="visible"
android:textCursorDrawable="#drawable/white_cursor" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="REGISTRATION"
android:id="#+id/regTitle_id"
android:layout_below="#+id/appLogoImage_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#ffffff"
android:textAlignment="center"
android:layout_marginTop="#dimen/margin_50"
android:visibility="invisible"
android:textStyle="bold" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions|text"
android:ems="10"
android:id="#+id/regName_id"
android:layout_below="#+id/loginPassword_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Your Good Name"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_marginTop="#dimen/margin_0"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regPassword_id"
android:layout_below="#+id/regName_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Application Password"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_marginTop="#dimen/margin_10"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regVerifyPass_id"
android:layout_below="#+id/regPassword_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Verify Password"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_marginTop="#dimen/margin_10"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regRingCode_id"
android:hint="Ringing Codeword"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regVerifyPass_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="#dimen/margin_10"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regLocationCode_id"
android:hint="Location Codeword"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/regRingCode_id"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="#dimen/margin_10"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/regNum1_id"
android:hint="1st Trusted Number"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regLocationCode_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="#dimen/margin_10"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:phoneNumber="false" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/regNum2_id"
android:hint="2nd Trusted Number"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regNum1_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="#dimen/margin_10"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:phoneNumber="false" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/regNum3_id"
android:hint="3rd Trusted Number"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regNum2_id"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="#dimen/margin_10"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:phoneNumber="false" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:id="#+id/regButton_id"
android:layout_below="#+id/regNum3_id"
android:layout_marginTop="#dimen/margin_15"
android:layout_alignLeft="#+id/appLogoImage_id"
android:layout_alignStart="#+id/appLogoImage_id"
android:layout_alignRight="#+id/appLogoImage_id"
android:layout_alignEnd="#+id/appLogoImage_id"
android:visibility="invisible" />
</RelativeLayout>
Your dimens.xml in res/values
<resources>
<dimen name="margin_10">10dp</dimen>
<dimen name="margin_0">0dp</dimen>
<dimen name="margin_15">15dp</dimen>
<dimen name="margin_30">30dp</dimen>
<dimen name="margin_50">50dp</dimen>
<dimen name="margin_20">20dp</dimen>
</resources>
I have a main_activity.xml that is displaying a fragmented layout. The layout contains imageview (a logo), and some text fields. At first, I tried to use relativelayout, it looks awesome/perfect on the design view. But when run on the emulater, everything jumble up. So I decided to use a LinearLayout. After changing, there's an improvement in the UI. But the problem is the image is not displaying.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout02">
<ImageView
android:id="#+id/imageView"
android:layout_width="276dp"
android:layout_height="276dp"
app:srcCompat="#drawable/splash_logob"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="276dp"
android:inputType="textPersonName"
android:text=""
android:hint="URL"
android:ems="10"
android:id="#+id/siteurl"
android:height="24sp"
android:layout_gravity="center"
android:background="#color/input_color"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingRight="5dp"
android:gravity="center"
android:paddingTop="3dp"
android:layout_centerHorizontal="true"
android:paddingLeft="5dp"
android:textAlignment="viewStart" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="276dp"
android:inputType="textPassword"
android:text=""
android:hint="Password"
android:ems="10"
android:id="#+id/password"
android:height="24sp"
android:layout_gravity="center"
android:background="#color/input_color"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingRight="5dp"
android:gravity="center"
android:paddingTop="3dp"
android:layout_centerHorizontal="true"
android:paddingLeft="5dp"
android:layout_marginTop="17dp" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="276dp"
android:inputType="textPersonName"
android:hint="username"
android:ems="10"
android:id="#+id/username"
android:height="24sp"
android:layout_gravity="center"
android:background="#color/input_color"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingRight="5dp"
android:gravity="center"
android:paddingTop="3dp"
android:layout_centerHorizontal="true"
android:paddingLeft="5dp"
android:layout_marginTop="17dp" />
</RelativeLayout>
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:textColor="#color/textcolor"
android:id="#+id/scannedresult"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/scanbtn"
android:layout_alignStart="#+id/scanbtn" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_height="wrap_content"
android:textColor="#color/textcolor"
android:text="QR Scanner"
android:id="#+id/scanbtn"
android:layout_width="wrap_content"
android:layout_alignRight="#+id/secretkey"
android:layout_alignEnd="#+id/secretkey"
android:layout_below="#+id/secretkey"
android:layout_alignBottom="#+id/login"
android:layout_weight="1" />
<Button
android:text="Login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="do_login"
android:layout_below="#+id/secretkey"
android:layout_alignLeft="#+id/secretkey"
android:layout_alignStart="#+id/secretkey"
android:id="#+id/login"
android:layout_weight="1" />
</LinearLayout>
<EditText
android:layout_width="wrap_content"
android:inputType="textPersonName"
android:text=""
android:hint="Secret Key"
android:height="24sp"
android:ems="10"
android:id="#+id/secretkey"
android:background="#color/input_color"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingRight="5dp"
android:paddingTop="3dp"
android:paddingLeft="5dp"
android:layout_marginTop="17dp"
android:layout_below="#+id/password"
android:layout_alignLeft="#+id/password"
android:layout_alignStart="#+id/password"
android:layout_alignRight="#+id/password"
android:layout_alignEnd="#+id/password" />
The problem is when i run, it did not display the image logo. What is wrong?
Screenshot
use:
android:src="#drawable/splash_logob"
instead of:
app:srcCompat="#drawable/splash_logob"
srcCompat attribute is defined within AppCompat library.
Change your imageview like this
<ImageView
android:id="#+id/imageView"
android:layout_width="276dp"
android:layout_height="276dp"
android:src="#drawable/splash_logob"
android:layout_centerHorizontal="true"
/>
I have set width of all the components to wrap_content in MainActivity but wrap_content does not works, I mean when I type into EditText then text appears only in limited width.
I want the TextViews and EditTexts to expand their widths according to input text length.
Please help, what is issue with my code?
MainActivity XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
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="com.example.appdeveloper.appname.MainActivity"
android:background="#ff003b"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/appLogoImage_id"
android:src="#drawable/applogo"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="You Can't Proceed Without Inserting Primary Sim (SIM-1) In Your Device!"
android:id="#+id/regNoSim_id"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textAlignment="center"
android:textColor="#ffffff"
android:visibility="invisible"
android:layout_below="#+id/appLogoImage_id"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="REGISTRATION"
android:id="#+id/regTitle_id"
android:layout_below="#+id/appLogoImage_id"
android:textColor="#ffffff"
android:textAlignment="center"
android:layout_marginTop="50dp"
android:visibility="invisible"
android:textStyle="bold"
android:layout_centerHorizontal="true"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/loginPassword_id"
android:overScrollMode="never"
android:scrollbars="none">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions|text"
android:ems="10"
android:id="#+id/regName_id"
android:hint="Your Name"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_marginTop="0dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regPassword_id"
android:layout_below="#+id/regName_id"
android:hint="Application Password"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regVerifyPass_id"
android:layout_below="#+id/regPassword_id"
android:hint="Verify Password"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regRingCode_id"
android:hint="Ringing Codeword"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regVerifyPass_id"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regLocationCode_id"
android:hint="Location Codeword"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regRingCode_id"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/regNum1_id"
android:hint="1st Trusted Number"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regLocationCode_id"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/regNum2_id"
android:hint="2nd Trusted Number"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regNum1_id"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/regNum3_id"
android:hint="3rd Trusted Number"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regNum2_id"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/regEmail_id"
android:hint="Email Address"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regNum3_id"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<Button
android:layout_width="230dp"
android:layout_height="wrap_content"
android:text="Register"
android:id="#+id/regButton_id"
android:visibility="invisible"
android:layout_centerHorizontal="true"
android:layout_below="#+id/regEmail_id"
android:layout_marginTop="15dp"
android:layout_marginBottom="20dp" />
</RelativeLayout>
</ScrollView>
<EditText
android:layout_width="wrap_content"
android:layout_height="50dp"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/loginPassword_id"
android:textAlignment="center"
android:hint="Enter Application Password"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:layout_below="#+id/appLogoImage_id"
android:layout_marginTop="50dp"
android:background="#android:color/transparent"
android:visibility="invisible"
android:textCursorDrawable="#drawable/white_cursor"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Forgotten Password?"
android:id="#+id/forgottenPass_id"
android:textAlignment="center"
android:textColor="#ffffff"
android:visibility="invisible"
android:layout_below="#+id/loginPassword_id"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:minHeight="30dp" />
</RelativeLayout>
Its because you have set android:ems="10" and that's the limitation remove it and see the difference!
You are thinking it's wrapped and adjust it's size because of your wrap_content but you have set android:ems !
Makes the TextView be exactly this many ems wide.
Refer : https://developer.android.com/reference/android/widget/TextView.html#attr_android:ems
[My Layout]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".Login"
android:background="#drawable/background">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/efield"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/textView_username" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Username :"
android:id="#+id/textView_username"
android:textColor="#FFFFFF"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="10dp"
android:layout_above="#+id/textView_attempt"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:gravity="right"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Password :"
android:id="#+id/textView_password"
android:textColor="#FFFFFF"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_above="#+id/textView_attempt_count"
android:layout_alignRight="#id/editText_pass"
android:layout_alignEnd="#id/editText_pass"
android:gravity="right" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/editText_user"
android:text="Name"
android:textColor="#FFFFFF"
android:layout_alignTop="#+id/textView_username"
android:layout_alignRight="#+id/imageView"
android:layout_alignEnd="#+id/imageView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/editText_password"
android:text="Password"
android:textColor="#FFFFFF"
android:layout_alignTop="#+id/textView_password"
android:layout_alignLeft="#id/textView_password"
android:layout_alignStart="#+id/editText_user" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Attempts :"
android:id="#+id/textView_attempt"
android:textColor="#FFFFFF"
android:paddingTop="40dp"
android:layout_centerVertical="true"
android:layout_alignRight="#+id/textView_username"
android:layout_alignEnd="#+id/textView_username" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textView_attempt_count"
android:layout_alignBottom="#+id/textView_attempt"
android:layout_alignLeft="#+id/editText_password"
android:layout_alignStart="#+id/editText_password"
android:textColor="#FFFFFF"/>
<Button
android:layout_width="160dp"
android:layout_height="40dp"
android:text="Login"
android:id="#+id/button_login"
android:background="#drawable/statelistdrawable"
android:textColor="#drawable/txco"
android:layout_above="#+id/textView_time"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView_time"
android:gravity="center"
android:textColor="#FFFFFF"
android:layout_above="#+id/button_FP"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="Forgot Password"
android:id="#+id/button_FP"
android:background="#android:color/transparent"
android:textColor="#drawable/tbutton"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
My Layout 1
Want to remove space between "Username" textview and "Name" edittext in Landscape. My layout is looking proper in portrait but gives space in between textview and edittext in landscape.
On this screenshot:
I am looking for the solution to make the UI more decent. I like the blue line for the input box but it only show either User Name or Password only. What is the simplest way to let the 2 blue line appear below User Name and Password in order?
Cheers
Here's what i have tried so far
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/myBackground"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="#drawable/voicemeno" />
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:layout_below="#+id/imageView1"
android:text="User Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/myText" />
<EditText
android:id="#+id/userNameInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_below="#+id/userName"
android:ems="10"
android:inputType="textPersonName"
android:textColor="#color/myText"
android:textCursorDrawable="#null" >
</EditText>
<TextView
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:layout_below="#+id/userNameInput"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/myText" />
<EditText
android:id="#+id/passwordInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_below="#+id/password"
android:ems="10"
android:inputType="textPassword"
android:textColor="#color/myText"
android:textCursorDrawable="#null" >
</EditText>
</RelativeLayout>
Edit:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/myBackground"
tools:context=".MainActivity"
android:selectAllOnFocus="true">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="#drawable/voicemeno" />
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:layout_below="#+id/imageView1"
android:text="User Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/myText" />
<EditText
android:id="#+id/userNameInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_below="#+id/userName"
android:ems="10"
android:inputType="textPersonName"
android:textColor="#color/myText"
android:textCursorDrawable="#null" >
</EditText>
<TextView
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:layout_below="#+id/userNameInput"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/myText" />
<EditText
android:id="#+id/passwordInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_below="#+id/password"
android:ems="10"
android:inputType="textPassword"
android:textColor="#color/myText"
android:textCursorDrawable="#null" >
</EditText>
</RelativeLayout>
you can use a TextView followed by a EditText view for each of the filds(username,password) you want.