XML in Android Studio: Wrapcontent in RelativeLayout - android

I need to have items arranged vertically in this order: TextView, LinearLayout (under the textview), then BottomNavigationView. But the result is this:
I have this code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:gravity="center"
android:layout_alignParentTop="true"
android:text="Home"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fragmentholder"
android:orientation="vertical"></LinearLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:menu="#menu/navigation"/>
</RelativeLayout>
What am I doing wrong?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="Home"
android:textSize="30dp" />
<LinearLayout
android:id="#+id/fragmentholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/message"
android:orientation="vertical"></LinearLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:menu="#menu/navigation" />
</RelativeLayout>
This comes in the order "TextView, LinearLayout (under the textview)" specified in the question.
The android:gravity="centre" feature is used to 'Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.' for the TextView.

Set this to the LinearLayout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/message"
android:layout_above="#+id/navigation"
android:id="#+id/fragmentholder"
android:orientation="vertical">
</LinearLayout>

ou can make something like this: with property layout_below
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:gravity="center"
android:layout_alignParentTop="true"
android:text="Home"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/message"
android:id="#+id/fragmentholder"
android:orientation="vertical"></LinearLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:menu="#menu/navigation"/>
</RelativeLayout>

Related

floating action button in linearlayout not showing

Hello I am trying to align a floating action button to the bottom right of the screen but its showing on the right top corner of the screen what can i do to make it to the bottom right?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="#style/AppTheme"
android:orientation="vertical"
tools:context=".MainActivity">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/createRoomButton"
style="#style/Widget.MaterialComponents.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
app:srcCompat="#drawable/ic_add_black_24dp"/>
<SearchView
android:id="#+id/searchInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:iconifiedByDefault="false"
android:queryHint="Search Rooms">
<requestFocus />
</SearchView>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/pullToRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/roomList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
Have made the necessary changes for your UI and now it works perfectly:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="#style/AppTheme"
android:orientation="vertical"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/createRoomButton"
style="#style/Widget.MaterialComponents.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="22dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
app:srcCompat="#drawable/ic_add_black_24dp"/>
<SearchView
android:id="#+id/searchInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:iconifiedByDefault="false"
android:layout_marginTop="50dp"
android:queryHint="Search Rooms">
<requestFocus />
</SearchView>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/pullToRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/roomList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>
</LinearLayout>

Recyclerview cannot be scrolled?

I have this screen.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"/>
</RelativeLayout>
<Button
android:id="#+id/btn_sync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="DoUpload"
android:text="Sync with server"
/>
</LinearLayout>
It looks like this (which is OK):
So I add more datas, now it looks like this:
The RecyclerView cannot be scrolled, and the button is hidden. How to fix this?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:layout_weight="1"/>
<Button
android:id="#+id/btn_sync"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:onClick="DoUpload"
android:text="Sync with server"/>
</LinearLayout >
</LinearLayout>
just copy this code and use it will be working fine
I have edited the code for you this will solve the problem and button will be at the end of RecyclerView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
<Button
android:id="#+id/btn_sync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/my_recycler_view"
android:layout_gravity="center_horizontal"
android:onClick="DoUpload"
android:text="Sync with server" />
</RelativeLayout>
</LinearLayout>
Try this,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<RelativeLayout
android:layout_above="#id/btn_sync"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"/>
</RelativeLayout>
<Button
android:id="#+id/btn_sync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:onClick="DoUpload"
android:text="Sync with server"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
Try using constraint layout like below
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="5dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#id/btn_sync"
android:scrollbars="vertical" />
<Button
android:id="#+id/btn_sync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:onClick="DoUpload"
android:text="Sync with server" />
</android.support.constraint.ConstraintLayout>
This layout should keep the button from hiding and recyclerview will scroll when more data items are added.
used nestedScrollView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>

Edittext and a button followed by recycler view

I have an empty Activity with RelativeLayout and RecyclerView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:="match_parent"
android:layout_height="match_parent"
app:layout_behavilayout_widthor="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
I need an EditText and a button to be added before RecyclerView.
I guess RecyclerView's padding height should be changed but not sure! Please help me
Try this out. Make your parent layout as Linear layout, your views will get stacked.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
android:layout_toStartOf="#+id/button" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Change the LinearLayout to "Vertical" orientation
Use android:layout_weight Property.
Indicates how much of the extra space in the LinearLayout is allocated
to the view associated with these LayoutParams.
Example
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/et_ONE"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/button_ONE"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Button"
android:layout_weight="1"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="3"/>
</LinearLayout>
You can try with
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavilayout_widthor="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/et_ONE"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/button_ONE"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Button"
android:layout_weight="1"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="3"/>
</LinearLayout>
</RelativeLayout>
is this you want?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EditText"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Use a LinearLayout before RecyclerView and and provide them an ID(e.g. temp) and use RelativeLayout property layout_below with the RecyclerView, like this android:layout_below="#id/temp"(it will make sure that your RecyclerView will always below then LinearLayout), Now Add your Button and EditText into that LinearLayout (Make sure that LinearLayout should be wrap_content into height)
Use this code, Edit according to your requirement
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:="match_parent"
app:layout_behavilayout_widthor="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main"
tools:context=".MainActivity">
<LinearLayout
android:id="#+id/temp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/temp" />
</RelativeLayout>
Hope it help!!

ImageView inside Toolbar is not well positioned on tablets

Image
I have a Toolbar with an ImageView inside. My problem is that this image is not positioned at the center of my Toolbar on tablets(it works fine on mobile devices). What can I do? Gravity doesn't work and I can't use a relative layout. There is an image on top showing my problem.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:design="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="mfceo.project.matiasnagore.powerlist.MainActivity">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="#+id/mainToolbar"
android:background="#fafafa"
android:titleTextColor="#ffffff"
android:layout_gravity="top">
<ImageView
android:id="#+id/imagePowerlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/powerlist"
android:scaleType="centerInside"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingLeft="55dp" />
</android.support.v7.widget.Toolbar>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#drawable/shadow_top"/>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ffffff">
</FrameLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#drawable/shadow"/>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
design:menu="#menu/bottom_nav_items"
design:itemIconTint="#drawable/selector"
design:itemTextColor="#drawable/selector"
android:background="#FFFAFAFA" />
</LinearLayout>
You need to add android:layout_gravity="top|center_horizontal" into your ImageView and remove paddings:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:design="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="mfceo.project.matiasnagore.powerlist.MainActivity"><android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="#+id/mainToolbar"
android:background="#fafafa"
android:titleTextColor="#ffffff"
android:layout_gravity="top">
<ImageView
android:id="#+id/imagePowerlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/powerlist"
android:scaleType="centerInside"
android:layout_gravity="top|center_horizontal"/>
</android.support.v7.widget.Toolbar>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#drawable/shadow_top"/>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ffffff">
</FrameLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#drawable/shadow"/>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
design:menu="#menu/bottom_nav_items"
design:itemIconTint="#drawable/selector"
design:itemTextColor="#drawable/selector"
android:background="#FFFAFAFA" /></LinearLayout>

Linear Layout does not fill the whole screen

Why the linear layout does not fill the whole screen?
As you can see I am using match parent in the linear layout.
If I delete the Scrollbar nothing changes. The button is not at the bottom of the screen.
main_activity.xml:
<?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:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
tools:context="com.sarahp.demo.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout ----------> HERE
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textview_demo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="32dp"
android:layout_marginTop="32dp"
android:text="#string/demo"
android:textSize="42dp"/>
<RelativeLayout
android:id="#+id/fragment_container_a"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:id="#+id/fragment_container_b"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#color/transparent"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
F A is the fragment part.
Give android:fillViewport="true" to your ScrollView.
Your xml will looks like below. Main_Activity.xml
<?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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Test Demo"
android:textStyle="bold"
android:gravity="center"/>
<RelativeLayout
android:id="#+id/fragment1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:background="#drawable/border_image">
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="center"
android:text="Test text Fragement1" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/fragment2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="center"
android:text="Test text Fragement2" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Remove the relative layout
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textview_demo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="32dp"
android:layout_marginTop="32dp"
android:text="#string/demo"
android:textSize="42dp"/>
<RelativeLayout
android:id="#+id/fragment_container_a"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:id="#+id/fragment_container_b"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#color/transparent"/>
</LinearLayout>
</ScrollView>

Categories

Resources