I have used SVG's for these icons, the icons are visible in xml but not visible in device .
following is my code :
` <LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="10"
>
<ImageView
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_weight="1.5"
app:srcCompat="#drawable/email_id_icon"
/>
<EditText
android:layout_width="0dp"
android:id="#+id/et_email"
android:layout_height="wrap_content"
android:layout_weight="8"
android:textColor="#fff"
android:inputType="textEmailAddress"
android:background="#android:color/transparent"
android:hint="Email Id"
android:textColorHint="#fff"
android:imeOptions="actionNext"
/>
</LinearLayout>`
I have gone through similar questions on SO, most of them suggested to use
android: src instead of app:srcCompat , but I have to use srcCompat only because of SVGs. So what should I do?
Edit -
I have done the same thing in another activity's layout .
here is the working code :
<LinearLayout
android:id="#+id/login_form_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/textView2"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="10">
<ImageView
android:id="#+id/username_iv"
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_weight="2"
app:srcCompat="#drawable/email_id_icon" />
<EditText
android:layout_width="0dp"
android:id="#+id/username_et"
android:layout_height="wrap_content"
android:layout_weight="8"
android:textColor="#fff"
android:inputType="textEmailAddress"
android:background="#android:color/transparent"
android:hint="Email Id"
android:textColorHint="#fff"
android:imeOptions="actionNext"
/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="10dp"
android:background="#fff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="10">
<ImageView
android:id="#+id/password_iv"
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_weight="2"
app:srcCompat="#drawable/password_icon" />
<EditText
android:id="#+id/password_et"
android:layout_height="wrap_content"
android:layout_weight="8"
android:layout_width="0dp"
android:background="#android:color/transparent"
android:textColor="#fff"
android:hint="Password"
android:inputType="textPassword"
android:fontFamily="roboto"
android:textColorHint="#fff"
/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="20dp"
android:background="#fff" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/btn_login"
android:layout_marginBottom="20dp"
android:background="#drawable/login_button_style"
android:text="Login"
android:textSize="#dimen/headingText"
android:textAllCaps="false"
android:textColor="#fff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_forgetpassword"
android:layout_marginBottom="10dp"
android:text="Forget your password ?"
android:textColor="#fff"
android:textSize="#dimen/headingText" />
</LinearLayout>
I did not want to have icons in 4 resolutions so I made a single .png image and converted into .svg using Android Studio's Vector asset .
Make sure you are using AppCompatActivity and not Activity. If you are using Activity, then write in your activity / fragment:
imageView.setImageResource(R.drawable.ic_svg_image);
Also add in build.gradle:
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
And for 4.x versions of Android you can also add a support for TextViews' inner drawables. This is also actual for ImageViews.
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// This flag should be set to true to enable VectorDrawable support for API < 21.
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
}
Then in AndroidManifest add this file:
<application
android:name=".MyApplication"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
...
</application>
Sometimes it crushes on some old devices. Then wrap your drawable inside:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_svg_image/>
</selector>
and set it instead of SVG:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/drawable"
/>
Add vectorDrawables in build.gradle (app)
defaultConfig { vectorDrawables.useSupportLibrary = true }
Then use androidx.appcompat.widget.AppCompatImageView instead of ImageView.
Make sure to use android:src to specify the svg added with Vector Asset tool.
Done!
you can use VectorDrawable
Here is a tool to convert you svg to VectorDrawable
On pre lollipop device svg support is not quite comprehensive.
Add this in your build.gradle
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
Late answer but hope it helps someone. If someone is using constraint layout as the parent, with android:layout_height="wrap_content" and if any of the inner views have android:layout_height="match_parent", then the inner view is not visible. Making the height of the inner elements to wrap content and constraining it to the top and bottom of the parent constraint layout element made it work for me.
Related
Here the image from my mobile:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="110dp"
android:layout_height="40dp"
android:text="Miles"
android:textSize="24sp"
android:visibility="visible"
tools:layout_editor_absoluteX="46dp"
tools:layout_editor_absoluteY="56dp"
tools:visibility="visible" />
<TextView
android:id="#+id/textView2"
android:layout_width="110dp"
android:layout_height="40dp"
android:text="Km"
android:textSize="24sp"
tools:layout_editor_absoluteX="46dp"
tools:layout_editor_absoluteY="140dp" />
<Button
android:id="#+id/buttonConvMilesToKm"
android:layout_width="287dp"
android:layout_height="54dp"
android:text="Convert Miles To Km"
android:textSize="18sp"
tools:layout_editor_absoluteX="62dp"
tools:layout_editor_absoluteY="209dp" />
<Button
android:id="#+id/buttonConvKmToMiles"
android:layout_width="280dp"
android:layout_height="60dp"
android:text="Convert Km To Miles"
android:textSize="18sp"
tools:layout_editor_absoluteX="65dp"
tools:layout_editor_absoluteY="284dp" />
<EditText
android:id="#+id/editTextMiles"
android:layout_width="200dp"
android:layout_height="50dp"
android:text="Convert Km To Miles"
android:textSize="18sp"
tools:layout_editor_absoluteX="179dp"
tools:layout_editor_absoluteY="46dp" />
<EditText
android:id="#+id/editTextKm"
android:layout_width="200dp"
android:layout_height="50dp"
android:ems="10"
android:inputType="textPersonName"
tools:layout_editor_absoluteX="179dp"
tools:layout_editor_absoluteY="130dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
This maybe a small error i did , but what am i missing so the interface appears to be overlapped . Im using Android Studio to develop this But the reference design looks alright unless i run it on emulator or my mobile itself . Im guessing im not wrong in coding the layouts n i even tried to change the way the layouts can be written
Your layout has no constraints. Please review the documentation on the valid ConstraintLayout XML attributes you can use to layout views relative to each other within a ConstraintLayout. You are looking for attributes like layout_constraintStart_toEndOf.
I made a sign-up activity in android studio with XML and tested it on first genymotion emulator with(S8 Android 7.1). The result was fine. But when I tested that on my Android Device (Samsung Galaxy J1 2016 Android 5.1), the layout is not completely visible, it is stretched from bottom.
I have tried to change the phone layout form 5inches (Pixel) to my smartphone size (4.5inches) but the result are same.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#drawable/bg"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="245dp">
<EditText
android:fontFamily="sans-serif"
android:inputType="text"
android:id="#+id/name"
android:textColor="#fff"
android:textColorHint="#fff"
android:background="#drawable/edit_text_style"
android:layout_width="320dp"
android:layout_height="50dp"
android:gravity="center"
android:hint="Username" />
<EditText
android:inputType="textEmailAddress"
android:textColor="#fff"
android:textColorHint="#fff"
android:background="#drawable/edit_text_style"
android:layout_width="320dp"
android:layout_height="50dp"
android:layout_marginTop="6dp"
android:gravity="center"
android:hint="Email" />
<EditText
android:inputType="textPassword"
android:textColor="#fff"
android:textColorHint="#fff"
android:background="#drawable/edit_text_style"
android:layout_width="320dp"
android:layout_height="50dp"
android:layout_marginTop="6dp"
android:gravity="center"
android:hint="Password" />
<EditText
android:inputType="phone"
android:textColor="#fff"
android:textColorHint="#fff"
android:background="#drawable/edit_text_style"
android:layout_width="320dp"
android:layout_height="50dp"
android:layout_marginTop="6dp"
android:gravity="center"
android:hint="Phone#" />
<Button
android:fontFamily="verdana"
android:textColor="#000"
android:background="#drawable/button_style_selector"
android:textSize="22dp"
android:textAllCaps="false"
android:text="Signup"
android:layout_marginTop="40dp"
android:layout_width="320dp"
android:layout_height="50dp" />
</LinearLayout>
</RelativeLayout>
This the screenshot of the Android Device result:
The simpliest solution is to used Constraint Layout
Here you use a paddingTop to 245dp, all phones doesn't have the same size so it's normal that in certain phone you get the cropped bottom.
Try with ConstraintLayout :)
Just remove the android:paddingTop="245dp", change layout_height to wrap_content and add android:layout_alignParentBottom="true" on the first LinearLayout and it should be fine.
using too much paddingTop with LinearLayoutfor this case is not good,
android:paddingTop="245dp"
instead you can use RelativeLayout with alignParentBottom="true" property and rearrange other views by layout_above property
Try this XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
android:orientation="horizontal"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="245dp">
<EditText
android:id="#+id/name"
android:layout_width="320dp"
android:layout_height="50dp"
android:layout_above="#+id/email_EditText"
android:background="#drawable/edit_text_style"
android:fontFamily="sans-serif"
android:gravity="center"
android:hint="Username"
android:inputType="text"
android:textColor="#fff"
android:textColorHint="#fff" />
<EditText
android:id="#+id/email_EditText"
android:layout_width="320dp"
android:layout_height="50dp"
android:layout_above="#+id/password_EditText"
android:layout_marginTop="6dp"
android:background="#drawable/edit_text_style"
android:gravity="center"
android:hint="Email"
android:inputType="textEmailAddress"
android:textColor="#fff"
android:textColorHint="#fff" />
<EditText
android:id="#+id/password_EditText"
android:layout_width="320dp"
android:layout_height="50dp"
android:layout_above="#+id/phone_EditText"
android:layout_marginTop="6dp"
android:background="#drawable/edit_text_style"
android:gravity="center"
android:hint="Password"
android:inputType="textPassword"
android:textColor="#fff"
android:textColorHint="#fff" />
<EditText
android:id="#+id/phone_EditText"
android:layout_width="320dp"
android:layout_height="50dp"
android:layout_above="#+id/signUp_Button"
android:layout_marginTop="6dp"
android:background="#drawable/edit_text_style"
android:gravity="center"
android:hint="Phone#"
android:inputType="phone"
android:textColor="#fff"
android:textColorHint="#fff" />
<Button
android:id="#+id/signUp_Button"
android:layout_width="320dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_marginTop="40dp"
android:background="#drawable/button_style_selector"
android:fontFamily="verdana"
android:text="Signup"
android:textAllCaps="false"
android:textColor="#000"
android:textSize="22dp" />
</RelativeLayout>
The way you are making your layout is not good at all. It may look great in one device and be awful in another.
First take a look at these topics:
https://developer.android.com/training/multiscreen/screensizes
https://developer.android.com/guide/practices/screens_support
But in my own experience ConstraintLayout can be not efficient to be used in some cases, the approach I choose in LinearLayouts. It may seems a little complex to use LinearLayout in all of your layout parts but it makes it much more flexible.
some times I face something like this:
<LinearLayout
<LinearLayout
<LinearLayout
....
But you know when its done it looks great. Of course you must know how to use some tools like weights etc. so I recommend you to use LinearLayout over Relative and don't use hard coded like paddingTop to `245dp.
The paddingTop of the LinearLayout you are using is much more than required. Try removing it.
But even then you want the same look, you can try wrapping your layout in a ScrollView like this:
<ScrollView
android:layout_height = "wrap_content"
android:layout_width = "match_parent">
<!-- All your Relative layout goes here -->
</ScrollView>
I am trying to resolve a Layout Margin issue, where after I run the app on the emulator the Status Text doesn't appear where I intend it to be.
Attached is the full layout code. How can I improve the code to mitigate this issue in the future?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
tools:context=".SettingsActivity">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/settings_profile_image"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="#drawable/default_profile" />
<TextView
android:id="#+id/settings_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="244dp"
android:text="#string/user_name"
android:textColor="#android:color/background_light"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/settings_user_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="260dp"
android:text="#string/user_profile_status"
android:textColor="#android:color/background_light"
android:textSize="18sp" />
</RelativeLayout>
What am I missing?
In the 1st place, you may want to try the constraint layout introduced by android as part of android material design which is aimed at avoiding all the overhead of nesting views. In constraint layout views can be dragged and drooped and they can be assigned margins in the multiples of 8. It is highly suggested to use constraint layouts as opposed to the old nesting of layouts.
if you want the status below user name, just use
android:layout_below="#+id/settings_username"
In your current layout, marginTop is useless, vertical position is decided by
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="260dp"
It is better to use ContraintLayout, which will remove all unused attributes (e.g, if margin is useless, margin attribute is automatically removed).
Try this You just have to remove android:layout_marginBottom="260dp" and android:layout_alignParentBottom="true" and Add android:layout_below="#+id/settings_username" in settings_user_status
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
tools:context=".SettingsActivity">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/settings_profile_image"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="#drawable/default_profile" />
<TextView
android:id="#+id/settings_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="244dp"
android:text="#string/user_name"
android:textColor="#android:color/background_light"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/settings_user_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_below="#+id/settings_username"
android:text="#string/user_profile_status"
android:textColor="#android:color/background_light"
android:textSize="18sp" />
</RelativeLayout>
I have bellow xml :
<RelativeLayout
android:id="#+id/relative_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/relative_two"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image_product_imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
<TextView
android:id="#+id/status_product_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:layout_marginTop="20dp"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:visibility="invisible" />
</RelativeLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/relative_three"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_below="#+id/relative_two">
<Spinner
android:id="#+id/select_spinner"
android:layout_width="15dp"
android:layout_height="0dp"
android:layout_marginRight="5dp"
android:dropDownVerticalOffset="40dp"
android:gravity="center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_default="wrap"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/name_product_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:ellipsize="marquee"
android:gravity="right"
android:maxLines="1"
android:text="TEXT"
app:layout_constraintRight_toLeftOf="#+id/select_spinner"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/count_products_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="right"
android:text="TEXT"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="#+id/select_spinner"
app:layout_constraintTop_toBottomOf="#+id/name_product_textview" />
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
In above xml I have bellow ImageView :
<ImageView
android:id="#+id/image_product_imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
Problem: My ImageView don't match in cardView (left and right and top).It has 2 or 3 space around ImageView(left and right and top).
In my source code I am setting Image like bellow :
Picasso.with(context)
.load(productsModelList.getPictureUrl())
.placeholder(AppCompatDrawableManager.get().getDrawable(context, R.drawable.placeholder_pictures))
.fit()
.into(image_product_imageview);
This space is the result of that CardView supports for system older than L (API 20). To make your layouts look the same either on the pre-Lollipop (and pre-CardView widget) or Lollipop and newer, Android introduced some additional attributes.
Because overlapping (rounding the corners) the content was difficult for older Android versions, the cardPreventCornerOverlap has been added and has been set by default as true. That is why there're white stripes around your ImageView - you can check by yourself that their width is closely related to the cardCornerRadius value.
To remove this padding turn off cardPreventCornerOverlap. You can do it:
via xml by card_view:cardPreventCornerOverlap="false"
or programatically by yourCardView.setPreventCornerOverlap(false).
Keep in mind that this gives you the effect you want only for API 20+.
On devices with older versions of a system, your rounded corners will be invisible (hidden under not-rounded image).
To know more check the CardView doc. In the first paragraph you can find the official note about your issue.
This question has been asked before, but I can't find a good answer that works for me.
Here is my XML code (updated):
<?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"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Account Name"
android:textSize="32dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="15dp"
android:id="#+id/textView" />
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/accountName"
android:background="#drawable/edit_text_background"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:padding="10dp"
android:backgroundTint="#color/abc_secondary_text_material_light" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Account Balance"
android:textSize="32dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="15dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:inputType="numberDecimal"
android:id="#+id/accountBalance"
android:background="#drawable/edit_text_background"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:padding="10dp"
android:backgroundTint="#color/abc_secondary_text_material_light"
android:text="£"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Button"
android:id="#+id/button"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
I've tried using android:windowSoftInputMode="adjustPan|adjustResize" however it hasn't worked.
I feel I'm doing something wrong with the layout of the XML code... It looks like this and I want the button to move up when the keyboard appears:
try using ScrollView at parent level
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
in your AndroidManifest.xml
android:windowSoftInputMode="stateVisible|adjustResize"
in style.xml file set your activity style as
<item name="android:windowActionBarOverlay">true</item>
make sure you are not using fullscreen activity.
I struggled with the same thing for long. The solution worked for me is by
adding below line to activity manifest.
android:windowSoftInputMode="stateHidden"
I request to keep the layout inside scrollview except the view(Button in this ques case) which you want move with keyboard.