Android Studio app does not fit on screen - java

I am new to Android Studio and can't seem to fix my app not fitting on my screen. I'm using Honor 8 for testing how the app looks and works but parts don't fit. I have tried including activity_main for different screen densities and and screen sizes, but nothing seems to work. Would appreciate some help.
Can not include images yet so here is manifest and activity_main.xml.
activity_main.xml:
`
<?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:id="#+id/parent">
<RelativeLayout
android:id="#+id/imageRel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:layout_alignParentTop="true">
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:minWidth="100dp"
android:minHeight="100dp"
android:src="#mipmap/ic_launcher" />
<Button
android:id="#+id/imgButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/image"
android:text="Press" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/inputRel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageRel"
android:layout_margin="20dp">
<EditText
android:id="#+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:width="170dp"
android:hint="Name" />
<EditText
android:id="#+id/emailTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/nameTxt"
android:layout_margin="10dp"
android:width="170dp"
android:hint="Email" />
<EditText
android:id="#+id/passwordTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/emailTxt"
android:layout_margin="10dp"
android:width="170dp"
android:password="true"
android:hint="Password" />
<EditText
android:id="#+id/reenterTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/passwordTxt"
android:layout_margin="10dp"
android:width="170dp"
android:password="true"
android:hint="Re-Enter Password" />
<TextView
android:id="#+id/genderTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/reenterTxt"
android:layout_margin="10dp"
android:text="Gender:" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/genderTxt"
android:layout_margin="10dp"
android:orientation="horizontal">
<RadioButton
android:id="#+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Male" />
<RadioButton
android:id="#+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
<RadioButton
android:id="#+id/radioOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Other" />
</RadioGroup>
<TextView
android:id="#+id/countryTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/radioGroup"
android:layout_margin="10dp"
android:text="Country:" />
<Spinner
android:id="#+id/countrySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioGroup"
android:layout_margin="10dp"
android:layout_toRightOf="#+id/countryTxt"
android:textColor="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/licenseRel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_toRightOf="#+id/inputRel"
android:layout_centerVertical="true">
<TextView
android:id="#+id/licenseTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/license_text" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/licenseCheck"
android:layout_below="#+id/licenseTxt"
android:layout_centerHorizontal="true"
android:text="I Agree" />
</RelativeLayout>
<Button
android:id="#+id/registerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Register"
android:layout_below="#id/inputRel"/>
</RelativeLayout>`
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.RegistrationApp">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Related

screen isn't scrolling up when the keyboard appers

screen isn't scrolling up when the keyboard appers. I've read many answers saying to use android:windowSoftInputMode="something" I tried many of them
android:windowSoftInputMode="adjustPan|adjustResize"
android:windowSoftInputMode="adjustResize"
android:windowSoftInputMode="adjustPan"
android:windowSoftInputMode="stateVisible|adjustResize"
android:windowSoftInputMode="stateVisible"
(also tried some others) none of them worked
I think the problem is on my xml which the most was generated by android studio "activity login" template.
is there any other way to do it?
my xml file
<LinearLayout 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:gravity="center_horizontal"
android:orientation="vertical"
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.eduardo.academia.LoginActivity">
<!-- 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" />
<ImageView
android:id="#+id/imageView"
android:layout_width="211dp"
android:layout_height="235dp"
app:srcCompat="#drawable/logo"
android:windowSoftInputMode="stateHidden"/>
<LinearLayout
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/action_sign_in"
android:textStyle="bold" />
<TextView
android:id="#+id/txtMudarSenha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center"
android:text="#string/forgot_password"
android:onClick="mudarSenha"
android:clickable="true"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.eduardo.academia">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:windowSoftInputMode="stateVisible|adjustResize"
android:name=".LoginActivity"
android:label="#string/title_activity_login"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ExerciciosActivity"
android:label="#string/title_activity_exercicios"
android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
</manifest>
You should use a ScrollView for this. try below xml for your layout
<ScrollView 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:fillViewport="true">
<LinearLayout 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:gravity="center_horizontal"
android:orientation="vertical"
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.eduardo.academia.LoginActivity">
<!-- 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" />
<ImageView
android:id="#+id/imageView"
android:layout_width="211dp"
android:layout_height="235dp"
app:srcCompat="#drawable/logo"
android:windowSoftInputMode="stateHidden"/>
<LinearLayout
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/action_sign_in"
android:textStyle="bold" />
<TextView
android:id="#+id/txtMudarSenha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center"
android:text="#string/forgot_password"
android:onClick="mudarSenha"
android:clickable="true"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>

Creating custom preference screen in android

I have created a PreferenceScreen(pref_screen.xml) for my settings menu. It contains list of objects with different categories. I have created another custom layout(settings.xml) containing buttons, views, texts, images.
I would like to know how can I display the contents of my custom layout in my PreferenceScreen.
This is my pref_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Flight Selection" >
<Preference
android:title="Change Flight"
android:selectable="true"
android:key="#string/choose_flight"
android:icon="#drawable/icon_select_flight" />
<Preference
android:title="Close Flight"
android:selectable="true"
android:key="#string/close_flight_successful"
android:icon="#drawable/icon_select_flight" />
</PreferenceCategory>
<PreferenceCategory
android:title="Terminal Panel" >
<Preference
android:title="Change Terminal"
android:selectable="true"
android:icon="#drawable/icon_terminal" />
</PreferenceCategory>
<PreferenceCategory
android:title="Printer Panel" >
<Preference
android:title="Choose Printer"
android:icon="#drawable/icon_printer" />
</PreferenceCategory>
<PreferenceCategory
android:title="AirFi Sync" >
<SwitchPreference
android:title="Enable Sync" />
<Preference
android:title="Sync Group"
android:icon="#drawable/airfi" />
<Preference
android:title="Sync Details"
android:icon="#drawable/airfi" />
</PreferenceCategory>
</PreferenceScreen>
And this is my settings.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/settings_content"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="vertical"
android:weightSum="10" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="35dp"
android:id="#+id/relativeLayout3">
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/transparent"
android:layout_below="#+id/relativeLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/view" />
<Button
android:layout_margin="10dp"
android:id="#+id/select_flight_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true" />
<Button
android:layout_margin="10dp"
android:id="#+id/close_leg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_margin="10dp"
android:visibility="visible"
android:id="#+id/configure_printer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/white_button_bg_state_list"
android:drawableLeft="#drawable/icon_printer"
android:maxHeight="#dimen/global_button_height"
android:minHeight="#dimen/global_button_height"
android:text="#string/choose_printer"
android:textColor="#drawable/custom_text_color_for_buttons"
android:textSize="#dimen/button_text_size"
android:textStyle="bold"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_margin="10dp"
android:visibility="visible"
android:id="#+id/configure_print_format"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/configure_printer"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/white_button_bg_state_list"
android:drawableLeft="#drawable/icon_printer"
android:maxHeight="#dimen/global_button_height"
android:minHeight="#dimen/global_button_height"
android:text="#string/change_printer_format"
android:textColor="#drawable/custom_text_color_for_buttons"
android:textSize="#dimen/button_text_size"
android:textStyle="bold" />
<Button
android:layout_margin="10dp"
android:visibility="visible"
android:id="#+id/configure_payment_device"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/white_button_bg_state_list"
android:drawableLeft="#drawable/icon_terminal"
android:maxHeight="#dimen/global_button_height"
android:minHeight="#dimen/global_button_height"
android:text="#string/change_payment_device"
android:textColor="#drawable/custom_text_color_for_buttons"
android:textSize="#dimen/button_text_size"
android:textStyle="bold"
android:layout_below="#+id/textView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:textStyle="bold"
android:textSize="20sp"
android:text="Terminal Panel"
android:textColor="#color/adyen_green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/close_leg"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/textView3" />
<TextView
android:textStyle="bold"
android:textSize="20sp"
android:text="Printing Panel"
android:textColor="#color/adyen_green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/configure_payment_device"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/textView4" />
</RelativeLayout>
<View
android:id="#+id/divider_net_sales"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:background="#color/transparent" />
<RelativeLayout
android:id="#+id/ifs_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:gravity="bottom">
<View
android:id="#+id/divider_ifs_panel"
android:layout_width="match_parent"
android:layout_height="1dp"
android:visibility="gone"
android:background="#color/transparent" />
<TextView
android:id="#+id/sync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_below="#id/divider_ifs_panel"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:text="#string/airfi_sync"
android:textSize="18sp"
android:visibility="gone"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
set layout for Individual preferenceScreenusing this :
<Preference
android:title="#string/label_pref_version"
android:key="#string/pref_version"
android:layout="#layout/pref" />
After this Use findViewById to access element of customlayout.

windowSoftInputMode does not pan Window

I don't know how to get my soft keyboard to show up under an TextView Field. It just covers up my Button and TextView.
I have used this link http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
as a reference. But it isn't working.
I have windowSoftInputMode="adjustPan" in the AndroidManifest file for my activity
<activity
android:name=".SearchView"
android:label="#string/title_activity_search_view"
android:parentActivityName=".MainActivity"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.txisystems.inventory.MainActivity" />
</activity>
Here is what the screen looks like without the soft keyboard.
and the code to go with it.
<?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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.mycompany.inventory.SearchView"
tools:showIn="#layout/activity_search_view">
<ImageView
android:id="#+id/logoView"
android:layout_width="225dp"
android:layout_height="90dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:src="#drawable/mylogo" />
<ProgressBar
android:id="#+id/progressBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/logoView"
android:layout_centerHorizontal="true"
android:visibility="invisible" />
<EditText
android:id="#+id/txtSearchField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/logoView"
android:layout_alignLeft="#+id/logoView"
android:layout_alignRight="#+id/logoView"
android:layout_alignStart="#+id/logoView"
android:layout_below="#+id/progressBar2"
android:inputType="textShortMessage"
android:maxLength="17"
android:maxLines="1"
android:capitalize="none" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/txtSearchField"
android:layout_marginBottom="15dp"
android:layout_marginTop="10dp"
android:background="#color/colorPrimary"
android:backgroundTint="#color/colorPrimaryDark"
android:onClick="doSearch"
android:text="Search"
android:textColor="#color/buttontext" />
<TextView
android:id="#+id/lblSearchMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/button"
android:layout_alignLeft="#+id/button"
android:layout_alignRight="#+id/button"
android:layout_alignStart="#+id/button"
android:layout_below="#+id/button"
android:gravity="center_horizontal"
android:text="Please enter 4 or more characters."
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/error"
android:textStyle="bold" />
</RelativeLayout>
Here is what happens (I used Photoshop to simulate the screen.)
The keyboard can't be dismissed and it covers the button and the message area.
And here is what I want to happen through the magic of Photoshop.
Use this in the Activity (OnCreate) which hosts the XML:
getActivity().getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

Activity relaunch when change from portrait to landscape mode

I build two XML-files for my activity. One in the layout Folder and the other in the layout-land folder. But when I change the orientation from portrait to landscape mode the activity relaunches. And thats exactly what i not want.
Because I'm plotting in three Graphs realtime data and the plotting should continue when I turn the Screen and not being interrupted or start new in any way.
Here is the first XML file in the layout-land Folder:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="496dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:id="#+id/my_layout" >
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Feuchtigkeit"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_alignLeft="#+id/sensor1_graph_Druck"
android:layout_alignParentTop="true" />
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Temperatur"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_alignLeft="#+id/sensor1_graph_Feuchtigkeit"
android:layout_below="#+id/sensor1_graph_Feuchtigkeit"
android:layout_marginTop="8dp" />
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Druck"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_below="#+id/sensor1_graph_Temperatur"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp" />
<Switch
android:id="#+id/mySwitch"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="#+id/sensor1_graph_Druck"
android:layout_centerHorizontal="false"
android:layout_marginTop="8dp"
/>
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/switchStatus"
android:layout_alignParentBottom="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/switchStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/mySwitch"
android:layout_alignBottom="#+id/mySwitch"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/mySwitch"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignLeft="#+id/mySwitch"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</ScrollView>
And here the second one in layout Folder:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="496dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:id="#+id/my_layout" >
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Feuchtigkeit"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_alignLeft="#+id/sensor1_graph_Druck"
android:layout_alignParentTop="true" />
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Temperatur"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_alignLeft="#+id/sensor1_graph_Feuchtigkeit"
android:layout_below="#+id/sensor1_graph_Feuchtigkeit"
android:layout_marginTop="8dp" />
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Druck"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_below="#+id/sensor1_graph_Temperatur"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp" />
<Switch
android:id="#+id/mySwitch"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="#+id/sensor1_graph_Druck"
android:layout_centerHorizontal="false"
android:layout_marginTop="8dp"
/>
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/switchStatus"
android:layout_alignParentBottom="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/switchStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/mySwitch"
android:layout_alignBottom="#+id/mySwitch"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/mySwitch"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignLeft="#+id/mySwitch"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</ScrollView>
In the Manifest XML it Looks like this:
<activity
android:name="com.TomKun.testgraph.DruckActivity"
android:label="#string/Sensor_1"
android:launchMode="singleTask"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
</activity>
If i have Manifest like this with
android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
</activity>
Then the layout does not change when I switch from Portrait to landscape mode. BUT the activity does not relaunch. Thats the one good thing
But if I do NOT use
android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
</activity>
the layout changes as i want but the activity is then relaunching.
So something in my implementation doesn't match.
Can anyone help me to solve this Problem?
I have seen that many people have similar Problems here on stackoverflow. But with these answers I couldn't solve my problem
Thanks in Advance!

Resize scrollview only in android

I have an android layout made like this:
--------------
| IMAGE1 |
--------------
| SCROLLVIEW |
--------------
| IMAGE2 |
--------------
When the keyboard pops up to input text in the scrollview's edittext, it resizes the whole application. Is there any way to keep IMAGE2 at the bottom of the screen?
The layout of the application:
<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="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".SignupActivity" >
<ImageView
android:id="#+id/Logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:src="#drawable/logo_1" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:scaleType="centerCrop"
android:src="#drawable/wave_2" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Logo" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="286dp"
android:fadingEdge="none"
android:orientation="vertical"
android:paddingBottom="30dp" >
<EditText
android:id="#+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/name" />
<EditText
android:id="#+id/editSurname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/surname" />
<EditText
android:id="#+id/editCompany"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/company" />
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<EditText
android:id="#+id/editUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/username" />
<EditText
android:id="#+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/password"
android:inputType="textPassword" />
<EditText
android:id="#+id/editMail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/mail"
android:inputType="textEmailAddress" />
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<EditText
android:id="#+id/editAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/address" />
<EditText
android:id="#+id/editZipCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/zipcode" />
<EditText
android:id="#+id/editCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/city" />
<EditText
android:id="#+id/editCountry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/country" />
<EditText
android:id="#+id/editPhone1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/phone" />
<EditText
android:id="#+id/editPhone2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="#string/mobilephone" />
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<Button
android:id="#+id/acceptButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="signup"
android:layout_gravity="center_horizontal"
android:text="#string/register" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Edit:
This is how actually the layout is. I want to keep the green wave image at the end of the page (under the keyboard) while still resizing the ScrollView to make it usable.
http://i.stack.imgur.com/ji1FB.png
http://i.stack.imgur.com/D4jcX.png
add this lines in your manifest in activity tag may be this works
<activity
android:name=".DemoActivity"
android:windowSoftInputMode="stateHidden|adjustResize" >
</activity>
If you want your IMAGE2 stuck at the bottom of the screen, put below code inside your activity tag in manifest.xml
<activity
.
.
android:windowSoftInputMode="adjustPan" >
</activity>
EDIT:
Try to put below tag along with the above mentioned one
android:windowSoftInputMode="stateVisible|adjustResize"
Let me know if this one works for you.
The problem is that your Button is part of the ScrollView. You should pull your Button out of the ScrollView and into the parent RelativeLayout, changing the attributes as follows:
<Button
android:id="#+id/acceptButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" //keep it to the bottom of the layout
android:onClick="signup"
android:layout_gravity="center_horizontal"
android:text="#string/register" />
Then your ScrollView will also need a modification:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Logo"
android:layout_above="#+id/acceptButton" //make it stay above the button
>
And given that you are using android:windowSoftInputMode="adjustResize", this should give you the correct behavior.
EDIT: Wait, if you just want the background to stay positioned, try just setting that image as your windowBackground in your Activity theme. (e.g. add android:windowBackground="#drawable/my_background_image" to the theme that your Activity uses).

Categories