RelativeLayout with two-dimensional scroll - android

I'm trying to create RelativeLayout with many widgets and I want to be able to scroll it vertically and horizontally.
At first, I made it to scroll only vertically with that xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical" >
<ScrollView
android:id="#+id/layoutPostWriteScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_marginRight="5dp"
android:fitsSystemWindows="true"
android:gravity="center" >
<TextView
android:id="#+id/layoutPostWriteCtrlLabelTheme"
style="#style/News.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Тема" />
<EditText
android:id="#+id/layoutPostWriteCtrlTheme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layoutPostWriteCtrlLabelTheme"
android:inputType="text" />
<LinearLayout
android:id="#+id/layoutPostWriteEmbeddedMediaLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteCtrlTheme"
android:gravity="left"
android:orientation="vertical" />
<Button
android:id="#+id/layoutPostWriteAddMediaButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteEmbeddedMediaLayout"
android:onClick="onAddMediaClick"
android:text="+ Добавить медиафайл" />
<TextView
android:id="#+id/layoutPostWriteCtrlLabelContent"
style="#style/News.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteAddMediaButton"
android:text="Содержание" />
<EditText
android:id="#+id/layoutPostWriteCtrlContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteCtrlLabelContent"
android:gravity="top"
android:inputType="textMultiLine"
android:lines="10"
android:scrollbars="vertical"
android:singleLine="false" />
<Button
android:id="#+id/layoutPostWriteCtrlSave"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_below="#id/layoutPostWriteCtrlContent"
android:background="#drawable/btn_save"
android:onClick="onClickSendPost" />
</RelativeLayout>
</ScrollView>
My activity looks like that:
Everything's allright and that activity scrolls vertically.
But then I tried to add horizontalScrollView like that:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical" >
<ScrollView
android:id="#+id/layoutPostWriteScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:fitsSystemWindows="true">
<HorizontalScrollView
android:id="#+id/layoutPostWriteHScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="fill"
android:fillViewport="true"
android:fitsSystemWindows="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_marginRight="5dp"
android:fitsSystemWindows="true"
android:gravity="center" >
<TextView
android:id="#+id/layoutPostWriteCtrlLabelTheme"
style="#style/News.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Тема" />
<EditText
android:id="#+id/layoutPostWriteCtrlTheme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layoutPostWriteCtrlLabelTheme"
android:inputType="text" />
<LinearLayout
android:id="#+id/layoutPostWriteEmbeddedMediaLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteCtrlTheme"
android:gravity="left"
android:orientation="vertical" />
<Button
android:id="#+id/layoutPostWriteAddMediaButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteEmbeddedMediaLayout"
android:onClick="onAddMediaClick"
android:text="+ Добавить медиафайл" />
<TextView
android:id="#+id/layoutPostWriteCtrlLabelContent"
style="#style/News.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteAddMediaButton"
android:text="Содержание" />
<EditText
android:id="#+id/layoutPostWriteCtrlContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteCtrlLabelContent"
android:gravity="top"
android:inputType="textMultiLine"
android:lines="10"
android:scrollbars="vertical"
android:singleLine="false" />
<Button
android:id="#+id/layoutPostWriteCtrlSave"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_below="#id/layoutPostWriteCtrlContent"
android:background="#drawable/btn_save"
android:onClick="onClickSendPost" />
</RelativeLayout>
</HorizontalScrollView>
</ScrollView>
There is no errors in markup but activity now looks like that:
All EditTexts and whole RelativeLayout shrinked. How can I make activity to look like at the first image, but scroll vertical and horizontal? I tried many combinations of layout_width and layout_height, but it seems to not work.

maybe it will helpful for you, there is a Link which describes how to make two dimensional scroll with ScrollView and HorizntalScrollView.

Related

Organizing layouts with edit text at bottom?

I wanted to make a layout with 3 LinearLayouts. In the 2nd LinearLayout I would have a ListView and the 3rd LinearLayout I would have an EditText and Button at the bottom. This was my attempt:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/view_post"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:background="#color/com_facebook_blue">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/view_status"/>
</LinearLayout>
<LinearLayout
android:id="#+id/view_comments"
android:layout_below="#+id/view_post"
android:layout_width="match_parent"
android:layout_height="250dp">
<ListView
android:id="#+id/lv_comments_feed"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
<LinearLayout
android:layout_below="#+id/view_comments"
android:id="#+id/send_message"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<EditText
android:id="#+id/write_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:gravity="top|left"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<Button
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
Now the design looks great but when I load the app on my phone, I have 2 problems:
I don't want to hardcode the LinearLayout heights. I have looked into layout_weight but I can't seem to have these layout_weights work without running into the 2nd problem below:
When I click the EditText, the EditText is hidden even though I have declared android:windowSoftInputMode="adjustResize|stateHidden" in my activity and I'm not sure why that's happening. Also, the EditText and Button are not directly at the bottom of the screen which is what I would want. Any help is appreciated, thanks!
you don't need to add listview as child of linear layout. and avoid fill_parent & use match_parent. if first linear layout is only for textview then don't use it inside of linearlayout. or only use wrap_content instead of a specific layout_height
Here i made some changes hope it will work
<?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">
<LinearLayout
android:id="#+id/view_post"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#222dc9">
<TextView
android:id="#+id/view_status"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/send_message"
android:layout_below="#id/view_post"
></ListView>
<LinearLayout
android:id="#+id/send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<EditText
android:id="#+id/write_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:gravity="top|left"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<Button
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
and use in Manifest with activity name is
android:windowSoftInputMode="adjustPan"
<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"
tools:context=".MainActivity">
<RelativeLayout
android:id="#+id/view_post"
android:layout_width="match_parent"
android:background="#color/material_grey_300"
android:padding="5dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/view_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/view_comments"
android:layout_above="#+id/send_message"
android:layout_below="#+id/view_post"
android:layout_width="match_parent"
android:background="#color/material_deep_teal_200"
android:padding="10dp"
android:layout_height="match_parent">
<ListView
android:id="#+id/lv_comments_feed"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</RelativeLayout>
<LinearLayout
android:id="#+id/send_message"
android:background="#color/material_blue_grey_800"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<EditText
android:id="#+id/write_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<Button
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:layout_weight="1"
android:text="send" />
</LinearLayout>
</RelativeLayout>

ScrollView Overlaps Toolbar

I'm trying to use ScrollView and Toolbar as the only childs of LinearLayout but they overlap each other. Searched a bit but didn't find anything useful, any idea how to solve this rather than giving padding/margin to ScrollView?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:float="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="right"
android:background="#color/white_dark_50">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar"
android:theme="#style/AppTheme"
android:scrollbarStyle="outsideOverlay"
android:gravity="center_vertical|right"
android:layout_alignParentTop="true"
android:background="#color/colorPrimary"
>
<!-- -->
</android.support.v7.widget.Toolbar>
<ScrollView
android:scrollbarStyle="outsideOverlay"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#color/white_dark_50" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="right"
android:background="#color/white_dark_50">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ایجاد جمله جدید"
android:id="#+id/new_sentence_title"
android:textColor="#color/midnight_blue"
android:layout_margin="10dp"
android:textStyle="bold"
android:gravity="center_vertical"
android:drawableRight="#drawable/ic_colored_doll"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_marginLeft="25dp"
android:layerType="software"
android:layout_marginRight="25dp"
android:background="#drawable/dashed_line" />
<com.wrapp.floatlabelededittext.FloatLabeledEditTextRightSided
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
float:fletPaddingLeft="10dp"
float:fletPaddingRight="10dp"
android:id="#+id/new_sentence_name"
float:fletPadding="10dp">
<EditText
android:layout_marginLeft="10dp"
android:id="#+id/new_sentence_name_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme"
android:backgroundTint="#color/accentColor"
android:singleLine="true"
android:textColor="#color/midnight_blue"
android:textColorHint="#color/hintColor"
android:maxLength="20"
android:drawableRight="#drawable/ic_name"
android:gravity="center_vertical|right"
android:hint="عنوان"/>
</com.wrapp.floatlabelededittext.FloatLabeledEditTextRightSided>
<com.wrapp.floatlabelededittext.FloatLabeledEditTextRightSided
android:layout_width="match_parent"
android:foregroundGravity="center_vertical|right"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
float:fletPaddingLeft="10dp"
float:fletPaddingRight="10dp"
android:id="#+id/new_sentence_period"
float:fletPadding="10dp">
<EditText
android:id="#+id/new_sentence_period_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme"
android:backgroundTint="#color/accentColor"
android:singleLine="true"
android:layout_marginLeft="10dp"
android:inputType="number"
android:textColor="#color/midnight_blue"
android:textColorHint="#color/hintColor"
android:maxLength="20"
android:drawableRight="#drawable/ic_name"
android:gravity="center_vertical|right"
android:hint="دوره تکرار"/>
</com.wrapp.floatlabelededittext.FloatLabeledEditTextRightSided>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginRight="5dp"
android:gravity="center_vertical|right">
<Spinner
android:id="#+id/repeat_kind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/AppTheme"
android:minHeight="25dp"
android:gravity="right"
android:layout_marginRight="5dp"
android:layout_marginLeft="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="نوع تکرار"
android:id="#+id/doll_type_tv"
android:textColor="#color/midnight_blue"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:drawableRight="#drawable/ic_doll"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginRight="5dp"
android:gravity="center_vertical|right">
<com.gc.materialdesign.views.ButtonFlat
android:id="#+id/date_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/blue"
android:text="Button"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="تاریخ تکرار"
android:textColor="#color/midnight_blue"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:drawableRight="#drawable/ic_doll"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginRight="5dp"
android:gravity="center_vertical|right">
<com.gc.materialdesign.views.ButtonFlat
android:id="#+id/time_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/blue"
android:text="Button"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="زمان تکرار"
android:textColor="#color/midnight_blue"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:drawableRight="#drawable/ic_doll"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|right">
<ImageView
android:id="#+id/doll_pic_IV"
android:layout_width="150dp"
android:layout_height="150dp"
style="#style/AppTheme"
android:minHeight="25dp"
android:scaleType="fitXY"
android:gravity="right"
android:layout_marginRight="5dp"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_image_add_to_photos"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="انتخاب صدا"
android:textColor="#color/midnight_blue"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:id="#+id/pic_tv"
android:drawableRight="#drawable/ic_image"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Apparently the problem wasn't overlapping Toolbar with ScrollView, but rather was with ScrollView itself. The problem was arrising from gravity of the only child on ScrollView, so removing gravity from LinearLayout inside ScrollView and the problem was solved. It seems like a bug to me maybe I should contact google and let them know 'bout this.
Try:
<LinearLayout>
<Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
This way the LinearLayout is going to firstly compute the dimension of the toolbar, because it has no layout_weight attributes, and lay it down. Then it assigns all the remaining space to the ScrollView.
i solved this by place toolbar and scroll view in relative layout, then give "android:layout_below="#+id/bar" " in scroll view..
just like this:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bar"
android:paddingTop="20dp"
android:layout_gravity="center">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"/></ScrollView></RelativeLayout>
For my problem: I'm rebuilding an activity into appCompatActivity while using a new standalone toolbar that was being overlapped by a scrollview. My solution was to give the toolbar elevation:
<android.support.v7.widget.Toolbar
...
android:elevation="3dp"
.../>
and increase the margin of the top item in my scrollview.
<EditText
...
android:layout_marginTop="80dp"
.../>
I solved this by adding this with this code, I hope it will help
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="false"
android:orientation="vertical"
android:padding="#dimen/activity_vertical_margin"
tools:context="tz.co.ikunda.MemberProfileActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="56dp"
android:orientation="vertical">
<TextView
android:id="#+id/tvMyView"
android:layout_width="match_parent"
android:text="You views goes between this scrollview layout"
android:layout_height="wrap_content" />
</ScrollView>
for me, problem solved simply by put my ScrollView in a Frame layout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
......
</ScrollView>
</FrameLayout>
For anyone experiencing similar issue with NestedScrollview, set marginTop of root component to that of actionBarSize, i.e.:
android:layout_marginTop="?attr/actionBarSize"

Can't get scrollview to work

my code of the XML file I am currently working in! So what I want is to make it possible to scroll in this screen, however there are currently no objects that fall outside of the screen but they will in the future. Hope This gives enough info for help.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
android:background="#666666">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="60dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Name: "
android:id="#+id/NameView" />
<TextView
android:layout_width="128dp"
android:layout_height="38dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/Name"
android:text="#string/nameString"
android:layout_gravity="center_horizontal"
android:layout_weight="0.75" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:weightSum="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Adress:"
android:id="#+id/AdresView" />
<TextView
android:layout_width="128dp"
android:layout_height="38dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/adressString"
android:id="#+id/Adress"
android:layout_gravity="center_horizontal"
android:layout_weight="0.75" />>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="60dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="E-mail:"
android:id="#+id/emailView"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="128dp"
android:layout_height="38dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/emailString"
android:id="#+id/Email"
android:layout_gravity="center_horizontal"
android:layout_weight="0.75" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="60dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Mobile:"
android:id="#+id/mobileView" />
<TextView
android:layout_width="128dp"
android:layout_height="38dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/mobileString"
android:id="#+id/Mobile"
android:layout_gravity="center_horizontal"
android:layout_weight="0.75" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edit Profile"
android:id="#+id/BeditProfile"
android:layout_gravity="bottom"
android:layout_marginLeft="240dp"
android:onClick="onButtonClick" />
</LinearLayout>
</ScrollView>
You need to use ScrollView instead of LinearLayout then i will be work.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#666666"
android:orientation="vertical"
android:weightSum="1" >
<!-- Your all XML code paste here -->
</LinearLayout>
</ScrollView>
If you want to make a screen scrollable just use a ScrollView.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
...
...
</LinearLayout>
</ScrollView>
The ScrollView must only have one direct child!
Put everything in one ScrollView and you will be able to scroll everything - so the main LinearLayout should be wrapped in a ScrollView

Keyboard overlaps Edit Text

Hello i have an activity which contains the following elements
this is my xml layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#dddddd">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#dddddd">
<TextView android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="title"
android:textSize="#dimen/checkout_title"
android:textColor="#858585"
android:textStyle="bold"
android:layout_margin="10dp" />
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="474dp"
android:layout_below="#+id/title"
android:layout_marginBottom="10dp"></android.support.v4.view.ViewPager>
<com.pockee.views.CirclePageIndicator android:id="#+id/indicator"
android:padding="0dp"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="#+id/pager"
app:pageColor="#858585"
app:fillColor="#f19201" />
<LinearLayout android:layout_below="#+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip"
android:background="#80000000"
android:layout_margin="10dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Value:"
android:textColor="#color/white" />
<EditText
android:id="#+id/value1"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#color/white"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:inputType="number" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dip"
android:text="Value2:"
android:textColor="#color/white" />
<EditText
android:id="#+id/value2"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:password="true"
android:background="#color/white"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:inputType="number" />
<Button
android:id="#+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:text="OK"
android:background="#f19100"
android:textColor="#color/white"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
in my manifest i'm using
android:windowSoftInputMode="adjustResize|stateVisible"
the problem is that the number keyboard overlaps edit text by 10 pixels
any ideas on this issue?
I see you have a relative layout wrapping your linear layout, yet both your linearLayout and relative layout have a margin of 10dp. Try editing the inner value 'LinearLayout' margin to 0 or changing margin altogether i.e use bottom-margin:0 instead of margin and reloading.

how to set a button at the bottom of a screen when the parent is a scroll view?

I have a scrollView (this is a solution to support landscape computability)
and in it one child- linearLayout.
I want to pose a button at the bottom of a screen.
layout_height = match_parent is problematic as the scroll can be infinite.
How can I do this, to be compatible to all screen resolution?
this is my xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.m"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue_bg" >
<LinearLayout
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<com.m.view.text.mTextView
android:id="#+id/verifyHeaderText"
style="#style/textOnBg"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginTop="50dp"
android:text="ENTER VERIFICATION CODE"
android:textAllCaps="true"
android:textColor="#android:color/white"
app:font_type="varela" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:paddingBottom="5dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="5dp" >
<LinearLayout
android:id="#+id/inputBox"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:background="#drawable/input_box_idle"
android:orientation="horizontal" >
<EditText
android:id="#+id/verificationCodeEditText"
style="#style/textOnBg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:hint="- - - - -"
android:inputType="number"
android:maxLength="5"
android:textColor="#00bcfe"
android:textSize="25dp"
android:textStyle="italic" >
</EditText>
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/continueButton"
style="#style/textOnBg"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:background="#drawable/btn_selector"
android:text="Continue"
android:textColor="#00bcfe"
android:textSize="16dp"
android:textStyle="italic" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
this is the result on wide-screen
The button is in the bottom of the scroll which spans 3/4 of the whole screen
Add android:fillViewport="true" to your scrollview:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.m"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue_bg"
android:fillViewport="true" >
Apply this to your layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Your scroll view -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginBottom="#dimen/ar_button_height"
android:gravity="center" >
<Button
android:id="#+id/button_at_bottom"
android:layout_width="match_parent"
android:layout_height="#dimen/ar_button_height"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal"
android:showDividers="middle" >
</Button>
</ScrollView>
</RelativeLayout>
Not sure if there is a better solution, but you could put your scroll view inside a relative layout and have your button outside the scroll view and set android:layout_alignParentBottom="true" on the button
If you want to set the button at the bottom you need to implement your layout with weight.
First of all the scrollview can only have one child layout inside it.
Secondly add your content layout inside the child layout of it, set the layout_height to 0dp, and do remember to set the weight to 1.
And at last add your button at the bottom of your content layout and set its height and set the weight to be 0.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/scrollMain"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="always"
android:background="#00000000"
android:scrollbars="none">
<LinearLayout
android:overScrollMode="always"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:background="#FFFFFF"
android:paddingTop="5dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
<Button android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_weight="0" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<com.m.view.text.mTextView
android:id="#+id/verifyHeaderText"
style="#style/textOnBg"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginTop="50dp"
android:text="ENTER VERIFICATION CODE"
android:textAllCaps="true"
android:textColor="#android:color/white"
app:font_type="varela" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:paddingBottom="5dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="5dp" >
<LinearLayout
android:id="#+id/inputBox"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:background="#drawable/input_box_idle"
android:orientation="horizontal" >
<EditText
android:id="#+id/verificationCodeEditText"
style="#style/textOnBg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:hint="- - - - -"
android:inputType="number"
android:maxLength="5"
android:textColor="#00bcfe"
android:textSize="25dp"
android:textStyle="italic" >
</EditText>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<Button
android:id="#+id/continueButton"
style="#style/textOnBg"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:background="#drawable/btn_selector"
android:text="Continue"
android:textColor="#00bcfe"
android:textSize="16dp"
android:textStyle="italic" />
USe your button here
You can use scrollView inside relativeLayout to fix your button at bottom:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/radialback">
<ScrollView android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="#+id/top_header"
>
<EditText
android:id="#+id/editmessage"
android:layout_margin="2dp"
style="#style/editView"
android:inputType="textMultiLine"
android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 _-.,()"
android:maxLength="500"
/>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/submitbutton"
android:text="#string/submitbutton"
style="#style/submitView"
android:layout_alignParentBottom="true" />
</RelativeLayout>

Categories

Resources