Use layout as background of another layout - android

Couldn't find this even though seems simple.
My question is simple, I have the following login layout:
<?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=".SignupActivity"
android:orientation="vertical"
android:background="#android:color/transparent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign Up"
android:textSize="48sp"
android:textColor="#color/white"
android:layout_gravity="center"
android:paddingTop="30dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="All fields are required."
android:layout_gravity="center"
android:paddingTop="100dp"/>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
app:cardElevation="20dp"
app:cardCornerRadius="15dp"
android:layout_gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Username"
android:layout_gravity="center"
android:id="#+id/usernametext"
android:padding="15dp"
android:ems="10"
android:textAlignment="center"/>
<EditText
android:id="#+id/passwordtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password"
android:layout_gravity="center"
android:padding="15dp"
android:inputType="textPassword"
android:textAlignment="center"/>
<EditText
android:id="#+id/emailtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:padding="15dp"
android:hint="Email"
android:textAlignment="center"
android:inputType="textEmailAddress" />
</LinearLayout>
</android.support.v7.widget.CardView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:id="#+id/submitButton"/>
</LinearLayout>
And I made another layout with just takes an ImageView and put it to the center with certain alpha.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/mtrigenicon"
android:alpha="0.25"
android:scaleX="3"
android:scaleY="3" />
</RelativeLayout>
Question is, It is possible to use the second layout as background of the first?, I mean, to use the ImageView below all the EditText and TextViews of the first layout, even integrating the ImageView on the first layout can work as a solution, but I don't know how to make it to be on the background and below all the other objects.

First you can include the imageview directly as background of login layout. Otherwise if you want to use second layout as background for any layout you can use <include tag in android xml.
Simply set your root layout to FrameLayout in which layout you want include background layout.
Like this
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:background="#android:color/transparent">
<include
layout="#layout/activity_background" /> //Here is the include part. Below as same as previous.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign Up"
android:textSize="48sp"
android:textColor="#android:color/white"
android:layout_gravity="center"
android:paddingTop="30dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="All fields are required."
android:layout_gravity="center"
android:paddingTop="100dp"/>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
app:cardElevation="20dp"
app:cardCornerRadius="15dp"
android:layout_gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Username"
android:layout_gravity="center"
android:id="#+id/usernametext"
android:padding="15dp"
android:ems="10"
android:textAlignment="center"/>
<EditText
android:id="#+id/passwordtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password"
android:layout_gravity="center"
android:padding="15dp"
android:inputType="textPassword"
android:textAlignment="center"/>
<EditText
android:id="#+id/emailtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:padding="15dp"
android:hint="Email"
android:textAlignment="center"
android:inputType="textEmailAddress" />
</LinearLayout>
</android.support.v7.widget.CardView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:id="#+id/submitButton"/>
</LinearLayout>
</FrameLayout>
activity_background.xml (Same as your layout)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/canoe_water_nature_480_670"
android:alpha="0.25"
android:scaleX="3"
android:scaleY="3" />
OUTPUT

Yes, it is possible. Try using this layout.
In xml views are drawn in the order you put them, so just put the image view first, and draw the linear layout on top. Like 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="match_parent">
<ImageView
android:layout_width="wrap_content"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/mtrigenicon"
android:alpha="0.25"
android:scaleX="3"
android:scaleY="3" />
Put your linear layout here
<LinearLayout></LinearLayout>
</RelativeLayout>

Instead of LinearLayout use RelativeLayout in your first layout and add your ImageView to it.
<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=".SignupActivity"
android:background="#android:color/transparent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="#drawable/mtrigenicon"
android:alpha="0.25"
android:scaleX="3"
android:scaleY="3" />
<TextView
android:id="+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign Up"
android:textSize="48sp"
android:layout_below="id/your_imageview_id"
android:textColor="#color/white"
android:layout_gravity="center"
android:paddingTop="30dp"/>
<TextView
android:id="+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="All fields are required."
android:layout_gravity="center"
android:layout_below="id/text1"
android:paddingTop="100dp"/>
<-- your rest of the layout -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:alignParentBottom="true"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:id="#+id/submitButton"/>
</RelativeLayout>
Make sure to configure your layout according to your requirement because LinearLayout does that automatically, but in RelativeLayout you have to do it on your own.

Related

Android LinearLayout overlapping imageView

I am trying to use a cardview to have an imageview and to the right of it a linearlayout, the problem i am having is the linearlayout is getting drawn on top of my imageview.
I am using a listview to get items and display each item on the menu.
The blue square is my linearlayout, the image is the highlighted part
axml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="8dp"
android:layout_margin="5dp"
android:background="#drawable/listitemshadow"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp">
<ImageView
android:id="#+id/menuItemImageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="5dp"
android:src="#drawable/picking" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:layout_marginLeft="0.0dp">
<TextView
android:id="#+id/menuItemNameTextView"
android:layout_width="200dp"
android:textSize="16dp"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:layout_alignParentLeft="true"
android:textStyle="bold"
android:gravity="left" />
<TextView
android:id="#+id/shortDescriptionTextView"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:textSize="12dp"
android:textColor="#android:color/black"
android:layout_below="#+id/menuItemNameTextView" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
You should use RelativeLayout otherwise you will have to use too many layouts that are bad for performance. And also don't use cardView as a parent because it will overlap the elements. Use it inside a RelativeLayout or a constraintLayout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/listitemshadow"
android:padding="8dp">
<ImageView
android:id="#+id/menuItemImageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="5dp"
android:src="#drawable/picking" />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/menuItemImageView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
android:paddingLeft="10dip">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0.0dp"
android:paddingLeft="10dip">
<TextView
android:id="#+id/menuItemNameTextView"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:textColor="#android:color/black"
android:textSize="16dp"
android:textStyle="bold" />
<TextView
android:id="#+id/shortDescriptionTextView"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/menuItemNameTextView"
android:gravity="left"
android:textColor="#android:color/black"
android:textSize="12dp" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
don't use card view as the main layout, always use another layout inside cardview because cardview works as frame layout, the whole thing put under another layout and that layout should under cardview
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:background="#drawable/ic_launcher_background"
android:padding="8dp"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/menuItemImageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:background="#color/colorPrimary"
android:padding="5dp"
android:src="#drawable/ic_launcher_foreground" />
<LinearLayout
android:id="#+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/menuItemImageView"
android:background="#color/colorAccent"
android:orientation="vertical"
android:paddingLeft="10dip">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0.0dp"
android:paddingLeft="10dip">
<TextView
android:id="#+id/menuItemNameTextView"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:textColor="#android:color/black"
android:textSize="16dp"
android:textStyle="bold" />
<TextView
android:id="#+id/shortDescriptionTextView"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/menuItemNameTextView"
android:gravity="left"
android:textColor="#android:color/black"
android:textSize="12dp" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
Try putting your linearlayout and image in another horizontal linearlayout instead of putting them directly inside cardview.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="8dp"
android:layout_margin="5dp"
android:background="#drawable/listitemshadow"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/menuItemImageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="5dp"
android:src="#drawable/picking" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:layout_marginLeft="0.0dp">
<TextView
android:id="#+id/menuItemNameTextView"
android:layout_width="200dp"
android:textSize="16dp"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:layout_alignParentLeft="true"
android:textStyle="bold"
android:gravity="left" />
<TextView
android:id="#+id/shortDescriptionTextView"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:textSize="12dp"
android:textColor="#android:color/black"
android:layout_below="#+id/menuItemNameTextView" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
In the card view, use a list view.
After that, make a custom layout for the list item i.e, make an XML file for the list item layout. After that create a custom adapter for adapting the list item to the list layout in the card view.
You can take the reference from this video:-
https://youtu.be/A-_hKWMA7mk

Android: How to center a LinearLayout between the screen and a button in RelativeLayout?

I have the following XML 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" >
<LinearLayout
android:id="#+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="false"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<EditText
android:id="#+id/login_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="#string/login_email"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="#string/login_password"
android:inputType="textPassword" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:text="#string/forgot_pass"
android:textAlignment="textEnd"
android:textColor="#android:color/holo_blue_dark" />
</LinearLayout>
<Button
android:id="#+id/login_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-5dip"
android:layout_marginLeft="-5dip"
android:layout_marginRight="-5dip"
android:layout_marginTop="-5dip"
android:background="#android:color/holo_blue_dark"
android:text="#string/login_button"
android:textColor="#android:color/background_light" />
</RelativeLayout>
As you can see I have a button that's on the bottom of my screen, but I want to centralize the LinearLayout between the top of the screen and the button, not the top of the screen with the bottom of the screen.
I've already tried android:layout_centerVertical="true" but it isn't what I want.
How do I proceed?
Use this code, and your linearlayout will be center aligned between top and bottom button
<?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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/login_btn"
>
<LinearLayout
android:id="#+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="false"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<EditText
android:id="#+id/login_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="#string/login_email"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="#string/login_password"
android:inputType="textPassword" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:text="#string/forgot_pass"
android:textAlignment="textEnd"
android:textColor="#android:color/holo_blue_dark" />
</LinearLayout>
</RelativeLayout>
<Button
android:id="#+id/login_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-5dip"
android:layout_marginLeft="-5dip"
android:layout_marginRight="-5dip"
android:layout_marginTop="-5dip"
android:background="#android:color/holo_blue_dark"
android:text="#string/login_button"
android:textColor="#android:color/background_light" />
</RelativeLayout>
Right now, it's centered relative to the parent element. If you want to center between the button and the top, you need another RelativeLayout that surrounds the LinearLayout with the button outside and make that match the parent boundaries. Then you center the LinearLayout in that. You might as well just make the outer element a LinearLayout.
Or you can also use a FrameLayout with center gravity around the inner LinearLayout
Or, ConstraintLayout might be even better
you don't have to add another relative layout for that
<?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" >
<LinearLayout
android:id="#+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="false"
android:layout_alignParentTop="true"
android:layout_above="#id/login_btn"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<EditText
android:id="#+id/login_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/login_email"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/login_password"
android:inputType="textPassword" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:text="#string/forgot_pass"
android:textAlignment="textEnd"
android:textColor="#android:color/holo_blue_dark" />
</LinearLayout>
<Button
android:id="#+id/login_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-5dip"
android:layout_marginLeft="-5dip"
android:layout_marginRight="-5dip"
android:layout_marginTop="-5dip"
android:background="#android:color/holo_blue_dark"
android:text="#string/login_button"
android:textColor="#android:color/background_light" />
</RelativeLayout>
Try this I hope this is what you are looking for?
your linear layout is covering all the area from the top of your screen till the top of the button.

RelativeLayout limits after adding ScrollView

I am adding a ScrollView as parent of a RelativeLayout, but when I do so my RelativeLayout limits to a little area and I can't change it.
When I change the padding I can fix the things in their place, but it is not a good way.
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relatOne"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp">
<!--textArea Title-->
<EditText
android:id="#+id/textArea"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#id/textView"
android:hint="Write your message here!"
android:linksClickable="true"
android:maxLines="6"
android:paddingLeft="20dp"
android:scrollbars="vertical"
android:textColorHint="#8e8e8e" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/textArea"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Text:"
android:textColor="#color/textAreaTitle"
android:textSize="20sp" />
<Button
android:id="#+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/btnColor"
android:onClick="btnSetter"
android:text="Set on Channel"
android:textAllCaps="false"
android:textColor="#ffffffff"
android:textSize="20sp"
android:textStyle="bold"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
You should make ScrollView as parent Root element not as Child in your case Change your Layout like this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:gravity="center">
<!--textArea Title-->
<EditText
android:id="#+id/textArea"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:hint="Write your message here!"
android:linksClickable="true"
android:maxLines="6"
android:paddingLeft="20dp"
android:scrollbars="vertical"
android:textColorHint="#8e8e8e" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_alignBaseline="#id/textArea"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Text:"
android:textSize="20sp" />
<Button
android:id="#+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:background="#000"
android:onClick="btnSetter"
android:text="Set on Channel"
android:textAllCaps="false"
android:textColor="#ffffffff"
android:textSize="20sp"
android:textStyle="bold"
/>
</LinearLayout>
</ScrollView>
Change Your Linear Layout gravity and margin according to your need
Screenshot of problem
I have this problem now after making ScrollView to root parent.

ScrollView: Button is not visible completely

I have a Problem with one activity xml in my Android project.
Its a ScrollView and inside i have a LinearLayout. In the LinearLayout i added a Button.
But the button is not completely visible. Only 2px or like that.
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/image_view_one"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Titel"
android:textSize="20dp"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:textColor="#000000"
android:id="#+id/textview_titel"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Content"
android:textSize="15dp"
android:layout_margin="10dp"
android:textColor="#000000"
android:id="#+id/textview_description"
/>
<android.support.v7.widget.AppCompatButton
android:id="#+id/btn_zum_gewinnspiel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:padding="12dp"
android:text="ZUM GEWINNSPIEL"
android:background="?attr/colorPrimary"
android:textSize="18dp"
/>
</LinearLayout>
</ScrollView>
Give bottomPadding in LinearLayout.

Android ScrollView not scrolling at all

Below is my XML code, I want the whole view to scroll, but it's just not working, please help, with what's wrong;
<?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="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/app_icon"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"/>
<TextView
android:id="#+id/textView_app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center"/>
<TextView
android:id="#+id/textView_content"
android:layout_width="match_parent"
android:layout_marginTop="15dp"
android:layout_height="386dp"
android:gravity="center"></TextView>
</LinearLayout>
</ScrollView>
I've tried using,
android:fillViewport="true"
but of no help.
A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects.
So here you have to take LinearLayout or RelativeLayout and then you have to put different hierarchy of component.
Android : buttons not visible in scrollview
here i have given answer of Some problem so you can follow this for solve your problem with clearing your concept.
Try like this ,Scrolling will work till End
<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">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/app_icon"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"/>
<TextView
android:id="#+id/textView_app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center"/>
<TextView
android:id="#+id/textView_content"
android:layout_width="match_parent"
android:layout_marginTop="15dp"
android:layout_height="386dp"
android:gravity="center"/>
</LinearLayout>
</ScrollView>
</Relativelayout>
If ScrollView fits to your device screen it would not be scrollable, so make sure content inside ScrollView takes space larger than your screen size.
systematix Try this,here you getting scroll.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/textView_app_version1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="hello" />
<TextView
android:id="#+id/textView_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/textView_app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="hello" />
<TextView
android:id="#+id/textView_content1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/textView_app_version2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="hello" />
<TextView
android:id="#+id/textView_content3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/textView_app_version4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="hello" />
<TextView
android:id="#+id/textView_content4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>
</LinearLayout>

Categories

Resources