Margin from top Doesn't working with RelativeLayout? - android

I have 5 button with an ImageView inside RelativeLayout and giving some margin to each of view from the top. But margin from top does not working in my condition.
My code is :
<?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" >
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<fragment
android:name="motorpool.orbitsysindia.com.motorpool.model.splash.view.fragment.FragmentHeaderLineColor"
android:layout_width="match_parent"
android:tag="#string/fragment_header"
android:layout_height="wrap_content">
</fragment>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_alignParentTop="true"
android:layout_below="#+id/header">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageCar"
android:layout_centerHorizontal="true"
android:src="#drawable/mu7"/>
<motorpool.orbitsysindia.com.motorpool.util.custom.ButtonBold
android:id="#+id/btnJointInsp"
style="#style/ButtonTextMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imageCar"
android:layout_marginTop="20dp"
android:text="#string/menuJointInsp" />
<motorpool.orbitsysindia.com.motorpool.util.custom.ButtonBold
android:id="#+id/btnVehRec"
style="#style/ButtonTextMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/btnJointInsp"
android:layout_marginTop="200dp"
android:text="#string/menuVehicleRec" />
<motorpool.orbitsysindia.com.motorpool.util.custom.ButtonBold
android:id="#+id/btnRecIns"
style="#style/ButtonTextMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/btnVehRec"
android:layout_marginTop="20dp"
android:text="#string/menuRecIns" />
<motorpool.orbitsysindia.com.motorpool.util.custom.ButtonBold
android:id="#+id/btnPdi"
style="#style/ButtonTextMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/btnRecIns"
android:layout_marginTop="20dp"
android:text="#string/menuPDI" />
<motorpool.orbitsysindia.com.motorpool.util.custom.ButtonBold
android:id="#+id/btnLocation"
style="#style/ButtonTextMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/btnPdi"
android:background="#drawable/vehicle_list"
android:text="#string/menuLocation" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/white"
android:gravity="center">
<fragment
android:name="motorpool.orbitsysindia.com.motorpool.model.splash.view.fragment.FragmentFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="#layout/fragment_footer" />
</RelativeLayout>
</RelativeLayout>
Any kind of help is Appreciated by me:

Problem android:layout_alignParentTop
If true, makes the top edge of this view match the top edge of the
parent. Accommodates top margin.
You should remove android:layout_alignParentTop="true" property .
EDIT
It is really just a bug of the RelativeLayout, so you could try to
wrap the RelativeLayout inside of a LinearLayout and set the margin
there.
Source .

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_alignParentTop="true"
android:layout_below="#+id/header">
Please remove android:layout_alignParentTop="true" from this relative layout

Related

Align Recycler View above linear layout

The list of things expected in the outout
1.a linear layout to the buttom of the activity as shown in the expected image
2.a recycler view above the linear layout to achieve the scrolling funtionality as shown in the expected image
The problem can be solved if I give the height to the recycler view.But in this case the layout won't be responsive to the samller sized screens
How can I achieve it?
xmlfile.xml
<?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:numberpicker="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:orientation="vertical"
tools:context=".CartPage">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:padding="20dp">
<ImageView
android:id="#+id/back_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:src="#drawable/ic_arrow_back_black_24dp" />
<TextView
android:id="#+id/product_buy"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/back_icon"
android:fontFamily="#font/carter_one"
android:text="My Cart"
android:textColor="#color/black"
android:textSize="20sp"
tools:ignore="RtlCompat" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/product_recycler"
android:layout_width="match_parent"
android:layout_height="400sp"
android:padding="0dp" />
// this is the buttom recycler
<LinearLayout
android:layout_alignParentBottom="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/buttom"
android:gravity="bottom|end"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border_gray"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="#+id/details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border_gray"
android:fontFamily="sans-serif"
android:lineHeight="28dp"
android:padding="5dp"
android:text="Price Details"
android:textColor="#color/grey_400"
android:textSize="18sp"
tools:ignore="RtlCompat" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
If you wish to tell your RecyclerView to fill the left over space of your LinearLayout you have to use the following layout_height and layout_weight on your RecyclerView:
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/product_recycler"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:padding="0dp" />

How to make Android xml Linerlayout at the bottom of the activity in Android Studio?

How do I make LinearLayout in Android Studio at the bottom of the page. The result from the code below
I want the highlighted darken layout to be at the bottom of the page.
<?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"
tools:context=".MainPage"
android:orientation="vertical"
android:background="#ffffff">
<Button
android:id="#+id/taptoscan"
android:layout_marginTop="40dp"
android:layout_marginBottom="10dp"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="#drawable/barcode"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tap to Scan"
android:fontFamily="#font/antic"
android:layout_gravity="center"
android:textSize="18sp"/>
<!--here is the layout i want to put at the bottom of the page-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#color/colorPrimaryDark"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:gravity="bottom">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RelativeLayout>
</LinearLayout>
In the above code I tried the below and did not worked.
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:gravity="bottom"
You can use RelativeLayout at the outside. Something like this, and then ADD new one LinearLayout after that.
<?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:background="#ffffff"
android:orientation="vertical"
tools:context=".MainPage">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/taptoscan"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:layout_marginBottom="10dp"
android:background="#drawable/barcode" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/antic"
android:text="Tap to Scan"
android:textSize="18sp" />
</LinearLayout>
<!--here is the layout i want to put at the bottom of the page-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="#color/colorPrimaryDark"
android:gravity="bottom"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
Use Frame Layout as base layout to do it in the best way, it's gonna work definitely
Just use layout_gravity="bottom" in the LinearLayout which you want at bottom and
Just like this :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="#ffffff"
android:orientation="vertical"
tools:context=".MainPage">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/taptoscan"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:layout_marginBottom="10dp"
android:background="#drawable/barcode" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/antic"
android:text="Tap to Scan"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="bottom"
android:background="#color/colorPrimaryDark"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
The approach below would help you achieve your design specifications with zero overlappings. Basically, there are four key steps:
Change your root layout to a RelativeLayout.
Inside the RelativeLayout, add a LinearLayout that would contain your Button and your TextView.
Inside the same RelativeLayout, add the LinearLayout that you intend to pin to the bottom of the screen.
Make sure yoU set the first LinearLayout on top of the second by using the android:layout_above="" attribute.
Now, here's the 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainPage">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff"
android:layout_above="#+id/bottomView">
<Button
android:id="#+id/taptoscan"
android:layout_marginTop="40dp"
android:layout_marginBottom="10dp"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="#drawable/barcode"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tap to Scan"
android:fontFamily="#font/antic"
android:layout_gravity="center"
android:textSize="18sp"/>
</LinearLayout>
<!--here is the layout i want to put at the bottom of the page-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/bottomView"
android:background="#color/colorPrimaryDark"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:gravity="bottom">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
I hope this helps.

android TextView: How to avoid line breaks?

I'm trying to figure out how to avoid line breaks within a TextView.
If the lines are too long for the width of TextView, a horizontal scroll bar should appear. Everything I tryed with android:scrollbars (and so on) failed, there are always line breaks. This is my layout code:
<?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="de.zpit2u.maingate.MainGate_Logs">
<TextView
android:id="#+id/tvTitle_Logs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="#string/app_logs" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/historyRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/tvTitle_Logs" >
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:fillViewport="false" >
<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="de.zpit2u.maingate.MainGate_Logs">
<TextView
android:id="#+id/tvTitle_Logs_Clients"
android:layout_marginTop="20dp"
android:layout_marginStart="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="#string/logs_clients" />
<TextView
android:id="#+id/tvText_Logs_Clients"
android:layout_below="#+id/tvTitle_Logs_Clients"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="10dp"
android:textSize="8sp"
android:fontFamily="monospace" />
<ProgressBar
android:id="#+id/progressBarLogs"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true" />
</RelativeLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
Second TextView (tvText_Logs_Clients) within the RelativeLayout should be horizontally scrollable.
the way to make textview scroll horizontally.
<HorizontalScrollView android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="40dp"
android:layout_height="wrap_content"
android:scrollHorizontally="true"
android:text="Horizontal scroll view will work now"/>
</HorizontalScrollView>

How to put a TextView under an ExpandableListView and make the ExpandableListView to fill the remaining space screen?

I want the ExpandableListView to fill the screen and I want to out the inner RelativeLayout below the ExpandableListView, but the ExpandableListView will fill the whole screen and I can't see the RelativeLayout.
What am I doing wrong?
I have this layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="#dimen/all_pages_padding_top"
tools:context="driver.mci.ir.mcicardriver.activity.MessagesActivity">
<ExpandableListView
android:id="#+id/messagesListView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#color/colorBackground"
android:layout_gravity="right|top">
</ExpandableListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/messagesListView"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<ImageButton
android:id="#id/imageView3"
android:layout_width="#dimen/login_icon_size"
android:layout_height="#dimen/login_icon_size"
android:scaleType="fitXY"
android:src="#drawable/sendmessage"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
/>
<EditText
android:id="#+id/userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView3"
android:layout_toStartOf="#+id/imageView3" />
</RelativeLayout>
</RelativeLayout>
Try this optimized layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingTop="#dimen/all_pages_padding_top"
tools:context="driver.mci.ir.mcicardriver.activity.MessagesActivity"
>
<ImageButton
android:id="#id/imageView3"
android:layout_width="#dimen/login_icon_size"
android:layout_height="#dimen/login_icon_size"
android:layout_alignParentBottom="true"
android:scaleType="fitXY"
android:src="#drawable/sendmessage"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
/>
<EditText
android:id="#+id/userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/imageView3"
android:layout_toStartOf="#+id/imageView3"
/>
<ExpandableListView
android:id="#+id/imageView3"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_above="#id/messagesListView"
android:background="#color/colorBackground"
android:layout_gravity="right|top"
/>
</RelativeLayout>
It's flatter (I got you rid of the extra nested layout). Therefore, more performant.
Try this,
Remove the ** in the layout I just used to highlight the lines
Quite not sure anybody can edit this comment to improve:
You gave the height for ExpandableListView as android:layout_height="match_parent" and after u r trying to put a layout with property below so its already taken the full height. But here I gave the bottom layout has to be the Relative layout the ExpandableListView has to come above the relative layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="#dimen/all_pages_padding_top"
tools:context="driver.mci.ir.mcicardriver.activity.MessagesActivity">
<ExpandableListView
android:id="#+id/messagesListView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#color/colorBackground"
**android:layout_above="#+id/textLayout"**
android:layout_gravity="right|top">
</ExpandableListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
**android:id="#+id/textLayout"**
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<ImageButton
android:id="#id/imageView3"
android:layout_width="#dimen/login_icon_size"
android:layout_height="#dimen/login_icon_size"
android:scaleType="fitXY"
android:src="#drawable/sendmessage"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
/>
<EditText
android:id="#+id/userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView3"
android:layout_toStartOf="#+id/imageView3" />
</RelativeLayout>

Android ScrollView not centering

I have the following code:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/activity_list_films">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:onClick="back"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
However the button, and the stuff that I add to the inner LinearLayout dynamically, all appear on the top left of the screen. What am I doing wrong?
I have tried putting layout_gravity="center" and gravity="center" in the inner LinearLayout too, but this does not help.
Thanks.
Your LinearLayout width is wrap_content : it doesn't take the whole width of the screen and cannot center content horizontally. So change it to android:layout_width="match_parent" also set layout_gravity to center_horizontal android:layout_gravity="center_horizontal"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/activity_list_films"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="back"
android:text="Back" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Try this
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity = "center"
android:gravity="center"
android:id="#+id/activity_list_films">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:onClick="back"/>
</LinearLayout>
</ScrollView>
Please set width -> match_parent of LinearLayout
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"<!--change this one -->
android:layout_height="wrap_content"
android:id="#+id/activity_list_films">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:onClick="back"/>
</LinearLayout>
Otherwise you can set you LinesrLayout in center. It will be in center of your ScrollView.
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/activity_list_films"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:onClick="back"/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="#+id/activity_list_films">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:onClick="back"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
You are missing fillViewPort for ScrollView
You not need to change Height of your Linear Layout inside Scroll View.
If you do that the content inside Scroll View will not scroll.
You just need to give android:layout_gravity="center_horizontal" inside Linear Layout other than keep all the same.
Follow below Layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/activity_list_films"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="back"
android:text="Back" />
</LinearLayout>
</ScrollView>
</LinearLayout>

Categories

Resources