i cannot place a relative layout below a sibling listView? - android

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">

Related

How can I Listview to fit?

I have a ListView which contains ImageView, TextView and Checkbox but,
When textView is long, checkBox is almost unavailable. I want to ListView to fit for a line.
How can I solve a problem that I have mentioned in the image?
ROW
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:padding="0dp"
android:weightSum="100" >
<ImageView
android:id="#+id/newImage"
android:layout_width="88dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:clickable="false"
android:hapticFeedbackEnabled="false"
android:saveEnabled="false" />
<TextView
android:id="#+id/newTaskTitle"
android:layout_width="wrap_content"
android:layout_height="63dp"
android:layout_alignParentTop="true"
android:layout_marginStart="11dp"
android:gravity="center_vertical"
android:text="Example"
android:textSize="20sp"
android:layout_weight="78.57" />
<CheckBox
android:id="#+id/checkBox"
android:layout_width="51dp"
android:layout_height="match_parent"
android:layout_weight="18.45"
android:gravity="left|center"
android:text="#string/checkBox" />
</LinearLayout>
</RelativeLayout>
LISTVIEW
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="203dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#android:color/transparent"
android:elevation="0dp"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme" />
Your Imageview width is already defined, So we should deal with 2 views and one should always be at right, and middle text to be flexible, so we can give weight to textview it will work fine.
You can try this,
<?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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<ImageView
android:id="#+id/newImage"
android:layout_width="88dp"
android:layout_height="match_parent"
android:clickable="false"
android:hapticFeedbackEnabled="false"
android:saveEnabled="false"/>
<TextView
android:id="#+id/newTaskTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="sdfsdfs"
android:textSize="20sp"/>
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left|center"
android:text="checkBox"/>
</LinearLayout>
</RelativeLayout>

Android Layout with Scrollview not at bottom - Fragment

What am I doing wrong that I can't get my "toolbar" to show up at the bottom of the screen (the free and post buttons)? I'm having to wrap this all inside a scroll view so that the keyboard will shift the view when displayed.
=======
UPDATE: Sorry I should have stated that the FREE and POST buttons must be at the bottom of the screen and maintain their size.
This is a FRAGMENT and the mainActivity has been set to android:windowSoftInputMode="adjustResize|adjustPan" however keyboard display is not scrolling the either.
<?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"
tools:context=".CreateFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/red">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/puregreen"
android:id="#+id/createTopView"
android:clickable="false">
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/createRecylerView" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:hint="Title"
android:textSize="24sp"
android:id="#+id/createTitleTextView"
android:layout_below="#+id/createRecylerView"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:hint="Description"
android:textSize="18sp"
android:id="#+id/createDescriptionTextView"
android:layout_below="#+id/createTitleTextView"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="+ Tags"
android:id="#+id/createTagsTextView"
android:textSize="18sp"
android:layout_above="#+id/createBottomToolbar"
android:layout_alignParentStart="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:id="#+id/createBottomToolbar"
android:layout_alignParentEnd="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FREE"
android:background="#drawable/button_rounded"
android:id="#+id/createCoinButton"
android:layout_alignParentLeft="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="POST"
android:id="#+id/createPostButton"
android:textColor="#ffffff"
android:layout_alignParentRight="true"
android:background="#color/my_blue" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
I have changed some code please try this code
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/createTopView"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:clickable="false">
<android.support.v7.widget.RecyclerView
android:id="#+id/createRecylerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_height="match_parent"
android:layout_below="#+id/createRecylerView">
<EditText
android:id="#+id/createTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/createRecylerView"
android:hint="Title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="24sp" />
<EditText
android:id="#+id/createDescriptionTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/createTitleTextView"
android:hint="Description"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="18sp" />
<EditText
android:id="#+id/createTagsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/createBottomToolbar"
android:text="+ Tags"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="18sp" />
<LinearLayout
android:orientation="horizontal"
android:id="#+id/createBottomToolbar"
android:layout_width="match_parent"
android:weightSum="1"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/createCoinButton"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="match_parent"
android:text="FREE" />
<Button
android:id="#+id/createPostButton"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="POST"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
Your toolbar is wrapped in a RelativeLayout which is wrapped in another RelativeLayout of which layout_height is set to wrap_content, here it is:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/red">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" <!-- here -->
android:background="#color/puregreen"
android:id="#+id/createTopView"
android:clickable="false">
Try changing this to match_parent and see if it works.
Why not use linearLayout as the child of scrollView? And set fillViewport property of the scrollView to true to stretch it's contents. Try this code:
<?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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".CreateFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="#color/red">
<LinearLayout
android:id="#+id/createTopView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/puregreen">
<android.support.v7.widget.RecyclerView
android:id="#+id/createRecylerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/createTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="24sp" />
<EditText
android:id="#+id/createDescriptionTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Description"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="18sp" />
<EditText
android:id="#+id/createTagsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="+ Tags"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="18sp" />
<RelativeLayout
android:id="#+id/createBottomToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/createCoinButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/button_rounded"
android:text="FREE"
android:textSize="14sp" />
<Button
android:id="#+id/createPostButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:background="#color/my_blue"
android:text="POST"
android:textColor="#ffffff"
android:textSize="14sp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>

Viewpager fragments not overlapping activity elements

I have a activity where i have some images,textview,a button and viewpager. Viewpager has height and width to match parent and all the layouts have background as white color . Now when the activity loads viewpager gets its fragments by adapter and it loads fragments. Now the images,textview are hidden behind the loaded fragments but the button does not gets hidden and its shown in fragments. Why is this happening ?
THis is my layout of activity with viewpager as last element
<?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"
tools:context="com.appointmentno.android.LogoFrontScreen"
android:background="#android:color/white"
android:keepScreenOn="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="#+id/rel_center_logo">
<ImageView
android:layout_width="#dimen/logo_width"
android:layout_height="#dimen/logo_height"
android:src="#drawable/finalc"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:id="#+id/img_logo_c"/>
<TextView
android:layout_width="210dp"
android:layout_height="wrap_content"
android:text="#string/logo_name"
android:layout_below="#id/img_logo_c"
android:id="#+id/app_name"
style="#style/RobotoTextViewStyle"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textSize="#dimen/logo_text_size"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/logo_underline"
android:layout_below="#id/app_name"
android:id="#+id/app_name_underline"
style="#style/RobotoTextViewStyle"
android:textColor="#android:color/black"
android:textSize="13sp"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_progress_report"
android:layout_below="#+id/rel_center_logo"
android:gravity="center"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true"
android:maxLines="10"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/str_2"
android:id="#+id/btn_enter_app"
android:layout_below="#id/rel_center_logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="84dp"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:id="#+id/logo_screen_progress"
android:layout_below="#id/rel_center_logo"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
android:id="#+id/txt_ver_alert"
android:gravity="center"/>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
</RelativeLayout>
Try this:
<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="com.appointmentno.android.LogoFrontScreen"
android:background="#android:color/white"
android:keepScreenOn="true"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="#+id/rel_center_logo"
android:orientation="vertical">
<ImageView
android:layout_width="#dimen/logo_width"
android:layout_height="#dimen/logo_height"
android:src="#drawable/finalc"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:id="#+id/img_logo_c"/>
<TextView
android:layout_width="210dp"
android:layout_height="wrap_content"
android:text="#string/logo_name"
android:id="#+id/app_name"
style="#style/RobotoTextViewStyle"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textSize="#dimen/logo_text_size"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/logo_underline"
android:id="#+id/app_name_underline"
style="#style/RobotoTextViewStyle"
android:textColor="#android:color/black"
android:textSize="13sp"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="#+id/rel_center_logo"
android:orientation="vertical"
android:layout_below="#id/rel_center_logo">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_progress_report"
android:gravity="center"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true"
android:maxLines="10"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/str_2"
android:id="#+id/btn_enter_app"
android:layout_centerHorizontal="true"
android:layout_marginTop="84dp"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:id="#+id/logo_screen_progress"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
android:id="#+id/txt_ver_alert"
android:gravity="center"/>
</LinearLayout>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
</RelativeLayout>
I basically divided your views into to groups (according to what I believe you want) and put them into their respective LinearLayouts. So in the end you have one RelativeLayout that holds two LinearLayouts and a ViewPager.

ScrollView inside a RelativeLayout

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"

ScrollView with sub RelativeLayout does not scroll

I have a ScrollView with 1 RelativeLayout which has 3 sub RelativeLayouts:
I set top RelativeLayout to alignParentTop="true",
The bottom RelativeLayout to alignParentBottom="true".
The middle layout to
android:layout_below="#id/topLayout"
android:layout_above="#+id/bottomLayout"
Problem: Scrollview does not scroll when screen is small, instead topLayout stays at top and bottomLayout stays at the bottom. The middle layout gets small and (even lost) as like below:
Desired: I want topLayout stay at top and bottomLayout stay at bottom. But when there is no space there must be scroll so they middle layout must not get lost.
Code:
<?xml version="1.0" encoding="utf-8"?>
<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:background="#color/white"
tools:context="com.jemshit.itu.fragments.TakeAttendanceFragment"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:paddingBottom="#dimen/halfClassic"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"
android:paddingTop="#dimen/halfClassic">
<RelativeLayout
android:id="#+id/layoutWeekChoice"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="0dp"
android:background="#color/white"
android:layout_alignParentTop="true">
<Spinner
android:id="#+id/spinnerWeekChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/buttonSetDate"
android:layout_toStartOf="#+id/buttonSetDate"
/>
<Button
android:id="#+id/buttonSetDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:maxWidth="150dp"
android:textSize="16sp"
android:text="Set Date"
android:gravity="center"
android:textColor="#color/white"
android:textAllCaps="false"
android:background="#drawable/button_background"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"
android:layout_alignBottom="#+id/spinnerWeekChoice"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutCardRead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:gravity="center"
android:layout_marginTop="32dp"
android:layout_below="#id/layoutWeekChoice"
android:layout_above="#+id/layoutShowAttendance"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageCard"
android:src="#drawable/std_card"
android:layout_alignParentTop="true"
android:layout_marginBottom="16dp"
android:layout_centerHorizontal="true"/>
<TextView
android:id="#+id/textWarningCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Checking..."
android:textColor="#color/black"
android:textSize="14sp"
android:layout_below="#+id/imageCard"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutShowAttendance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/halfClassic"
android:background="#color/white"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/textAttended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attended: "
android:textColor="#color/black"
android:layout_alignParentTop="true"
android:textSize="16sp"/>
<TextView
android:id="#+id/textNotAttended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not Attended: "
android:textColor="#color/black"
android:textSize="16sp"
android:layout_marginBottom="32dp"
android:layout_below="#+id/textAttended"/>
<Button
android:id="#+id/buttonManualAttendance"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:text="Manual Attendance"
android:gravity="center"
android:textAllCaps="false"
android:textSize="16sp"
android:textColor="#color/white"
android:background="#drawable/button_background"
android:minHeight="50dp"
android:layout_below="#id/textNotAttended"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
Note: I do not want to use LinearLayout with weight="1" which will make my 3 layouts same height
EDIT: now ScollView scrolls with new code below but my bottom TextViews get lost:
Code Updated:
<?xml version="1.0" encoding="utf-8"?>
<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:background="#color/white"
tools:context="com.jemshit.itu.fragments.TakeAttendanceFragment"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:paddingBottom="#dimen/halfClassic"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"
android:paddingTop="#dimen/halfClassic">
<RelativeLayout
android:id="#+id/layoutWeekChoice"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="0dp"
android:background="#color/white"
android:layout_alignParentTop="true">
<Spinner
android:id="#+id/spinnerWeekChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/buttonSetDate"
android:layout_toStartOf="#+id/buttonSetDate"
/>
<Button
android:id="#+id/buttonSetDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:maxWidth="150dp"
android:textSize="16sp"
android:text="Set Date"
android:gravity="center"
android:textColor="#color/white"
android:textAllCaps="false"
android:background="#drawable/button_background"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"
android:layout_alignBottom="#+id/spinnerWeekChoice"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutCardRead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:gravity="center"
android:layout_marginTop="32dp"
android:layout_below="#id/layoutWeekChoice"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageCard"
android:src="#drawable/std_card"
android:layout_alignParentTop="true"
android:layout_marginBottom="16dp"
android:layout_centerHorizontal="true"/>
<TextView
android:id="#+id/textWarningCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Checking..."
android:textColor="#color/black"
android:textSize="14sp"
android:layout_below="#+id/imageCard"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutShowAttendance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/halfClassic"
android:background="#color/white"
android:layout_below="#id/layoutCardRead"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/textAttended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attended: "
android:textColor="#color/black"
android:layout_above="#+id/textNotAttended"
android:textSize="16sp"/>
<TextView
android:id="#+id/textNotAttended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not Attended: "
android:textColor="#color/black"
android:textSize="16sp"
android:layout_marginBottom="32dp"
android:layout_above="#+id/buttonManualAttendance" />
<Button
android:id="#+id/buttonManualAttendance"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:text="Manual Attendance"
android:gravity="center"
android:textAllCaps="false"
android:textSize="16sp"
android:textColor="#color/white"
android:background="#drawable/button_background"
android:minHeight="50dp"
android:layout_alignParentBottom="true"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
Set your parents RelativeLayout height to wrap_content. Match_parent needs only ScrollView, everything inside it can spend all the space it needs.
From your 2nd relative layout,that is layoutcard remove android:layout_above="#+id/layoutShowAttendance"
and from layoutShowAttendance remove
android:layout_alignParentBottom="true"
and add android:layout_below="#+id/layoutCardRead" to layoutShowAttendance
It will work.

Categories

Resources