I need to do a scroll view inside a relative layout.
When I added the ScrollView this was the result http://postimg.org/image/6abxth299/ where the components are are only taking up half of the screen and when this screen is opened the keyboard comes up by default
<?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"
android:scrollbars="vertical" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:layout_centerHorizontal="true"
android:id="#+id/data_entry_layout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Post Title"
android:id="#+id/post_title"
android:layout_alignBaseline="#+id/post_title_input"
android:layout_alignBottom="#+id/post_title_input"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="26px"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/post_title_input"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="#+id/post_title"
android:layout_toEndOf="#+id/post_title"
android:inputType="textCapSentences"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Post Description"
android:id="#+id/post_description"
android:layout_below="#+id/post_title_input"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="39dp"
android:textSize="26px"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine|textCapSentences"
android:ems="10"
android:id="#+id/editText"
android:layout_marginTop="16dp"
android:layout_below="#+id/post_description"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageButton1"
android:layout_below="#+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:baselineAlignBottom="false"
android:contextClickable="true"
android:src="#drawable/image_button_icon"
android:onClick="galleryIntent"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:id="#+id/cancel"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#id/imageButton1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="#+id/submit"
android:layout_alignTop="#+id/cancel"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_below="#id/imageButton1"/>
</RelativeLayout>
</ScrollView>
The height of first dirsct child of scrollview, be it relative or linear layout should be wrap content and not match parent. Also the inner childs should have specific weight or height and not match parent like you have done for imageButton.
Try adding below to your AndroidManifest in your this activity to remove keyboard comes up by default
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
and Use android:layout_height="wrap_content" for scrollview , sugesting to use LinearLayout with vertical orientation layout for this kind of use.
I think ScrollView doesn't work inside Relativelayout. It's better to use LinearLayout.
Try this one...
<?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:fillViewport="true">
<RelativeLayout
android:id="#+id/data_entry_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<RelativeLayout
android:id="#+id/Rel12345"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/post_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/post_title_input"
android:layout_alignBottom="#+id/post_title_input"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Post Title"
android:textSize="26px" />
<EditText
android:id="#+id/post_title_input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_toEndOf="#+id/post_title"
android:layout_toRightOf="#+id/post_title"
android:inputType="textCapSentences" />
<TextView
android:id="#+id/post_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/post_title_input"
android:layout_marginTop="39dp"
android:text="Post Description"
android:textSize="26px" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/post_description"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="textMultiLine|textCapSentences" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText"
android:baselineAlignBottom="false"
android:contextClickable="true"
android:onClick="galleryIntent"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/Rel1234"
android:layout_below="#id/Rel12345"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Cancel"/>
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/cancel"
android:text="Submit" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
and Try adding below to your AndroidManifes to remove keyboard coming by default
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
Related
I've searched it everywhere, and I've come up wrapping all my content inside a ScrollView, and setting the keyboard this way:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
But when I enable the keyboard by tapping the EditText, all the content gets pushed up except for a TextView in the Top part, why is that?
XML Layout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<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="wrap_content"
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.FET.leonardo.scurcola.NameSelection"
android:background="#e0ab18">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/whoMaster"
android:textColor="#color/white"
android:textSize="50sp"
android:layout_marginTop="50dp"
android:textAlignment="center"
android:id="#+id/whoMaster"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="#string/master"
android:ems="10"
android:textColorHint="#color/white"
android:textColor="#color/white"
android:textColorHighlight="#color/white"
android:id="#+id/names"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/next"
android:layout_marginBottom="50dp"
android:onClick="onClick"
android:text="#string/next"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/names"
android:textColor="#e0ab18" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/back"
android:id="#+id/back"
android:enabled="false"
android:onClick="onClick"
android:textColor="#e0ab18"
android:layout_marginBottom="50dp"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/names" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/finish"
android:visibility="gone"
android:text="#string/finish"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/names"
android:layout_marginBottom="50dp"
android:onClick="onClick"
android:textColor="#e0ab18"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/zero"
android:textSize="50sp"
android:textColor="#color/white"
android:id="#+id/playersLeft"
android:layout_below="#+id/names"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
</RelativeLayout>
Instead of RelativeLayout try to use Linear Layout after scrollView.Set Orientation to Vertical.
I am trying to implement a scrollview in one of my XML files but it doesnt seem to be working. It is cutting out the bottom 3 spinners and the last button in the XML. I guessed this is because I needed to scroll down to see them but I am unable to scroll?
Can anyone seem the issue?
XML
<?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:fillViewport="true"
>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:id="#+id/title"
android:text="New Recipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
<EditText
android:id="#+id/recipeName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:hint="Enter Recipe Name"/>
<ListView
android:id="#+id/ingredientsList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/recipeName"
android:textColor="#000000"
android:layout_above="#+id/showIngredientDialog"
android:minHeight="150px">
</ListView>
<Button
android:id="#+id/showIngredientDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Ingredient"
android:layout_above="#+id/showDirectionDialog"
android:layout_alignParentStart="true"
android:layout_marginBottom="145dp" />
<ListView
android:id="#+id/directionsList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_above="#+id/showDirectionDialog"
android:layout_alignParentStart="true"
android:layout_marginBottom="37dp">
</ListView>
<Button
android:id="#+id/showDirectionDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Direction"
android:layout_marginBottom="79dp"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/showIngredientDialog" />
<Spinner
android:id="#+id/timeSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/showDirectionDialog"
android:entries="#array/time"/>
<Spinner
android:id="#+id/dietarySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/dietary"
android:layout_below="#+id/showDirectionDialog"
android:layout_toRightOf="#+id/timeSpinner" />
<Spinner
android:id="#+id/heatSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/heat"
android:layout_below="#+id/showDirectionDialog"
android:layout_toRightOf="#+id/dietarySpinner" />
<Button
android:id="#+id/saveRecipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Recipe"
android:layout_below="#+id/timeSpinner"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/showDirectionDialog"
android:layout_marginBottom="25dp" />
</RelativeLayout>
</ScrollView>
Your facing this issue because you are using ScrollView in which having ListView. Both having default scroll property which conflicting the issue. Check this SO post for resolving the issue.
Set the relativeLayout height to "wrap_content".
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<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">
<TextView
android:id="#+id/title"
android:text="New Recipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
<EditText
android:id="#+id/recipeName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:hint="Enter Recipe Name"/>
<ListView
android:id="#+id/ingredientsList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/recipeName"
android:textColor="#000000"
android:layout_above="#+id/showIngredientDialog"
android:minHeight="150px">
</ListView>
<Button
android:id="#+id/showIngredientDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Ingredient"
android:layout_above="#+id/showDirectionDialog"
android:layout_alignParentStart="true"
android:layout_marginBottom="145dp" />
<ListView
android:id="#+id/directionsList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_above="#+id/showDirectionDialog"
android:layout_alignParentStart="true"
android:layout_marginBottom="37dp">
</ListView>
<Button
android:id="#+id/showDirectionDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Direction"
android:layout_marginBottom="79dp"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/showIngredientDialog" />
<Spinner
android:id="#+id/timeSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/showDirectionDialog"
android:entries="#array/time"/>
<Spinner
android:id="#+id/dietarySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/dietary"
android:layout_below="#+id/showDirectionDialog"
android:layout_toRightOf="#+id/timeSpinner" />
<Spinner
android:id="#+id/heatSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/heat"
android:layout_below="#+id/showDirectionDialog"
android:layout_toRightOf="#+id/dietarySpinner" />
<Button
android:id="#+id/saveRecipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Recipe"
android:layout_below="#+id/timeSpinner"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/showDirectionDialog"
android:layout_marginBottom="25dp" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
you can't put two scrolling widgets inside one another the will cause major issues even with normal scrolling
if there is no way to change this layout design please force a height to each listview but still the scroll will be buggy and you have to set extra margin on the side of list for the user to be able to scroll the parent scroll view
or try to break down the design if you can maybe tabs one for normal data and a tab for each list
Because views of total heigt not bigger than screen height.
You can see with coding custom height. I hope below code help you.
I just change listview height.
<?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:fillViewport="true"
>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:id="#+id/title"
android:text="New Recipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
<EditText
android:id="#+id/recipeName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:hint="Enter Recipe Name"/>
<ListView
android:id="#+id/ingredientsList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/recipeName"
android:textColor="#000000"
android:layout_above="#+id/showIngredientDialog"
android:minHeight="150px">
</ListView>
<Button
android:id="#+id/showIngredientDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Ingredient"
android:layout_above="#+id/showDirectionDialog"
android:layout_alignParentStart="true"
android:layout_marginBottom="145dp" />
<ListView
android:id="#+id/directionsList"
android:layout_width="fill_parent"
android:layout_height="1000dp"
android:textColor="#000000"
android:layout_above="#+id/showDirectionDialog"
android:layout_alignParentStart="true"
android:layout_marginBottom="37dp">
</ListView>
<Button
android:id="#+id/showDirectionDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Direction"
android:layout_marginBottom="79dp"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/showIngredientDialog" />
<Spinner
android:id="#+id/timeSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/showDirectionDialog"
/>
<Spinner
android:id="#+id/dietarySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/showDirectionDialog"
android:layout_toRightOf="#+id/timeSpinner" />
<Spinner
android:id="#+id/heatSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/showDirectionDialog"
android:layout_toRightOf="#+id/dietarySpinner" />
<Button
android:id="#+id/saveRecipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Recipe"
android:layout_below="#+id/timeSpinner"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/showDirectionDialog"
android:layout_marginBottom="25dp" />
</RelativeLayout>
Ok I am trying to create a screen with a lot of buttons on it, obviously I ran out of space so I set my layout to a ScrollView with a relative layout underneath it and then placed all of my buttons inside that.
heres the code:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="1000dp" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:fillViewport="true"
tools:context="com.cecode.www.gjcode.MainTypes"
android:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Options Menu(placeholder)"
android:id="#+id/optionsBtn"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="400dp"
android:layout_height="80dp"
android:text="Top Text"
android:id="#+id/button1"
android:layout_marginTop="110dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
<Button
android:layout_width="400dp"
android:layout_height="80dp"
android:text="placeholder text"
android:id="#+id/button2"
android:layout_marginTop="20dp"
android:layout_below="#+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="400dp"
android:layout_height="80dp"
android:text="placeholder text"
android:id="#+id/button3"
android:layout_marginTop="20dp"
android:layout_below="#+id/button2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="400dp"
android:layout_height="80dp"
android:text="placeholder text"
android:id="#+id/button4"
android:layout_marginTop="20dp"
android:layout_below="#+id/button3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="mid text"
android:id="#+id/textView3"
android:layout_below="#+id/button4"
android:layout_alignRight="#+id/optionsBtn"
android:layout_alignEnd="#+id/optionsBtn"
android:layout_marginTop="37dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="bottom text"
android:id="#+id/textView4"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/textView3"
android:layout_alignStart="#+id/textView3" />
</RelativeLayout>
</ScrollView>
heres a screenshot of the screen-
My problem is that when I test this on a device it will not scroll past the mid text point, so I cannot get to the bottom text bit. Thanks!
replace
android:layout_height="1000dp"
with
android:layout_height="match_parent"
and let me know if it works
ok as you specified as per your requirement you can use LinearLayout with verticla orientation and between mid and bottom text put another linear layout with wrap_content height to add your buttons if you want some space before adding buttons to it you can specify minheight to layout take look at below code
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:fillViewport="true"
tools:context="com.cecode.www.gjcode.MainTypes"
android:animateLayoutChanges="true">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Options Menu(placeholder)"
android:id="#+id/optionsBtn"
/>
<Button
android:layout_width="400dp"
android:layout_height="80dp"
android:text="Top Text"
android:id="#+id/button1"
android:layout_marginTop="110dp"
/>
<Button
android:layout_width="400dp"
android:layout_height="80dp"
android:text="placeholder text"
android:id="#+id/button2"
android:layout_marginTop="20dp"
/>
<Button
android:layout_width="400dp"
android:layout_height="80dp"
android:text="placeholder text"
android:id="#+id/button3"
android:layout_marginTop="20dp"
/>
<Button
android:layout_width="400dp"
android:layout_height="80dp"
android:text="placeholder text"
android:id="#+id/button4"
android:layout_marginTop="20dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="mid text"
android:id="#+id/textView3"
/>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:orientation="vertical">
<!-- add your button here -->
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="bottom text"
android:id="#+id/textView4"
/>
</LinearLayout>
</ScrollView>
it is really hard to catch your requirements. Let me explain how it works at the moment. ScrollView doesn't give exact height so when you set match_parent for relative layout I guess it sets max height for this view - Integer.MAX_VALUE. That is why Android Studio warns you to change match_parent to wrap_content.
If you need this view in the bottom - set the margin of your bottom view in runtime.
I have this xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="blocked"
android:id="#+id/isBlocked_cb"
android:layout_toStartOf="#+id/phone_editText"
android:layout_toLeftOf="#+id/phone_editText"
android:layout_above="#+id/comments_list"
android:checked="true" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<AutoCompleteTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/phone_editText"
android:hint="enter phone"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="search"
android:id="#+id/search_btn"
android:layout_toEndOf="#+id/phone_editText"
android:layout_toRightOf="#+id/phone_editText"
android:layout_above="#+id/comments_list"
android:layout_alignParentTop="true" android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" android:onClick="foo"/>
<ListView
android:layout_width="match_parent"
android:layout_height="430dp"
android:id="#+id/comments_list"
android:layout_below="#+id/phone_editText"/>
<RelativeLayout android:id="#+id/bottom_container"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="#id/item_list"
android:visibility="visible">
<AutoCompleteTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="#+id/comment_text"
android:hint="enter comment"/>
<Button style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"
android:id="#+id/add_btn"
android:layout_toRightOf="#+id/comment_text"
android:layout_alignTop="#+id/comment_text"/>
</RelativeLayout>
<LinearLayout
android:focusable="true" android:focusableInTouchMode="true"
android:layout_width="0px" android:layout_height="0px"/>
</RelativeLayout>
but yet i cannot place the list above the bottom container.
why cannot i use wrap content for the latter both height ?
the list view has the wrong id of comments_list, lets change it to item_list so that bottom_container will be placed below it.
<ListView
android:layout_width="match_parent"
android:layout_height="430dp"
android:id="#+id/item_list"
android:layout_below="#+id/phone_editText"/>
<RelativeLayout android:id="#+id/bottom_container"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="#id/item_list"
android:visibility="visible">
I'm building an android app and I am trying to set my layout without any success.
I searched everywhere and I can't seem to find any solution.
I need to place 2 text views on top of an image.
the first text view need to be about 10dp above the vertical center of the image.
and the second text view should be below text view 1.
here's my code so far, though it doesn't work.
can anyone here tell me what I'm missing or what am I doing wrong?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
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.boromedia.parve.MainActivity" >
<RelativeLayout
android:id="#+id/blueOvalLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="75sp" >
<ImageView
android:id="#+id/blueOval"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="#drawable/blueoval" />
<ImageView
android:id="#+id/greenOval"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="#drawable/greenoval_small"
android:visibility="gone" />
<TextView
android:id="#+id/greenOvalText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="65dp"
android:gravity="center|center_vertical"
android:text="#string/counter_activity_oval_done"
android:textColor="#fff"
android:textSize="28sp"
android:visibility="gone" />
<TextView
android:id="#+id/blueOvalText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/counter_activity_oval_text1"
android:textColor="#fff"
android:textSize="18sp" />
<TextView
android:id="#+id/blueOvalTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/blueOvalText"
android:layout_centerHorizontal="true"
android:text="#string/counter_default"
android:textColor="#fff"
android:textSize="25sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
<TextView
android:id="#+id/head_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:gravity="center_vertical|center"
android:text="#string/main_title"
android:textSize="30sp" />
<Button
android:id="#+id/stopButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#android:color/transparent"
android:text="#string/counter_activity_stop_button"
android:textSize="20sp" />
Try this workaround: Change your textView for:
<RelativeLayout
android:id="#+id/wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="10dp" >
<TextView
android:id="#+id/blueOvalText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/counter_activity_oval_text1"
android:textColor="#fff"
android:textSize="18sp" />
</RelativeLayout>
This is a wrapper for setting the margin of 10dp.
Don't forget that your second textview should be below the wrapper, not below the textview!
I hope this would help;)
You can put your 2 TextView in a LinearLayout which will be centered in the parent :
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true" >
<TextView
android:id="#+id/blueOvalText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/counter_activity_oval_text1"
android:textColor="#fff"
android:textSize="18sp" />
<TextView
android:id="#+id/blueOvalTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/blueOvalText"
android:layout_centerHorizontal="true"
android:text="#string/counter_default"
android:textColor="#fff"
android:textSize="25sp" />
</LinearLayout>