Scrollview hiding the textview text in landscape mode - android

I am trying to use the scrollview to make the textview wrapped within it scrollable.
I am using the grid layout and am able to position the items as I need to, particularly the long text block, wrapped in a scroll view (the text under the big heading).
However, upon rotating , the long text block disappears completely and I have to keep scrolling it up to make it visible. I need it to be visible as expected when in landscape mode.
landscape mode, now visible after swiping up
This is my XML
<?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">
<include layout="#layout/toolbar" android:id="#+id/toolbar"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_marginTop="20dp"
android:id="#+id/articlesummaryimageview"
android:layout_below="#id/toolbar"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/articlesummaryheadingtextview"
android:layout_below="#id/articlesummaryimageview"
android:layout_centerHorizontal="true"
android:textSize="26dp"
android:textStyle="bold"
android:textAlignment="center"
android:layout_marginTop="20dp"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/articlesummaryscreenscrollview"
android:layout_below="#id/articlesummaryheadingtextview"
android:fillViewport="false"
android:layout_above="#+id/showfullarticlebutton"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/articlesummarytextview"
android:textSize="18dp"
android:textAlignment="center"
android:padding="5dp"
/>
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/showfullarticlebutton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textSize="18dp"
android:text="Full Article"
style="#style/AlertDialog.AppCompat.Light"
/>
</RelativeLayout>
Thank you

You're going to have to make your whole layout scrollable or come up with a different design. To make the whole layout scrollable, put the RelativeLayout inside the ScrollView and set the layout_height for the ScrollView to be wrap_content.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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/articlesummaryscreenscrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<include
layout="#layout/toolbar"
android:id="#+id/toolbar"
/>
<ImageView
android:id="#+id/articlesummaryimageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/toolbar"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<TextView
android:id="#+id/articlesummaryheadingtextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/articlesummaryimageview"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textAlignment="center"
android:textSize="26dp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/articlesummarytextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:textAlignment="center"
android:textSize="18dp"
android:layout_above="#+id/showfullarticlebutton"
android:layout_below="#id/articlesummaryheadingtextview"
/>
<Button
android:id="#+id/showfullarticlebutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Full Article"
android:textSize="18dp"
style="#style/AlertDialog.AppCompat.Light"
/>
</RelativeLayout>
If your business rules don't allow for the entire layout to be scrollable, what you can do is put your ScrollView as the first layout in the XML and adjust your other views layout_above and layout_below to that initial one (basically making that the view that is always shown and everything else adjust around it).
<?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"
>
<ScrollView
android:id="#+id/articlesummaryscreenscrollview"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_above="#+id/showfullarticlebutton"
android:fillViewport="false"
>
<TextView
android:id="#+id/articlesummarytextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:textAlignment="center"
android:textSize="18dp"
/>
</ScrollView>
<TextView
android:id="#+id/articlesummaryheadingtextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/articlesummaryscreenscrollview"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textAlignment="center"
android:textSize="26dp"
android:textStyle="bold"
/>
<ImageView
android:id="#+id/articlesummaryimageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/articlesummaryheadingtextview"
android:layout_below="#id/toolbar"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<Button
android:id="#+id/showfullarticlebutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Full Article"
android:textSize="18dp"
style="#style/AlertDialog.AppCompat.Light"
/>
</RelativeLayout>

1. Add RelativeLayout as a direct child of ScrollView and put TextView inside it.
2. Use attributge android:fillViewport="true" to ScrollView.
Try this:
<?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">
<include layout="#layout/toolbar" android:id="#+id/toolbar"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_marginTop="20dp"
android:id="#+id/articlesummaryimageview"
android:layout_below="#id/toolbar"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/articlesummaryheadingtextview"
android:layout_below="#id/articlesummaryimageview"
android:layout_centerHorizontal="true"
android:textSize="26dp"
android:textStyle="bold"
android:textAlignment="center"
android:layout_marginTop="20dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/articlesummaryscreenscrollview"
android:layout_below="#id/articlesummaryheadingtextview"
android:fillViewport="true"
android:layout_above="#+id/showfullarticlebutton">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/articlesummarytextview"
android:textSize="18dp"
android:textAlignment="center"
android:padding="5dp"
android:text="this is a text"/>
</RelativeLayout>
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/showfullarticlebutton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textSize="18dp"
android:text="Full Article"
style="#style/AlertDialog.AppCompat.Light" />
</RelativeLayout>

Related

overlapping a screen in android

In the below layout i have a text view named as scanning device.In that am displaying a device name But my device list was displaying above the screen .
can any one please help me how to scroll view should be inside the device list.while scrolling the screen it was displaying the list of the devices but it is displaying above the screen.
want to display inside a screen.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="#string/back"
android:textAllCaps="true"
android:textColor="#color/white"
android:visibility="invisible" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:padding="10dp"
android:textStyle="bold"
android:text="#string/lamp_list"
android:textAllCaps="true"
android:textColor="#color/white" />
<TextView
android:id="#+id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableRight="#drawable/refresh"
android:gravity="right"
android:padding="10dp"
android:textAllCaps="true"
android:textColor="#color/white" />
<ProgressBar
android:id="#+id/scanningProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:background="#drawable/baground"
android:orientation="vertical">
<TextView
android:id="#+id/scan_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="18dp"
android:gravity="center"
android:text="#string/start_discovery"
android:textColor="#color/white"
android:visibility="gone"
tools:visibility="visible" />
<android.support.v7.widget.RecyclerView
android:id="#+id/deviceListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
In the below layout connect textview was coming out of the layout.
device_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="6dp"
android:src="#drawable/lamp" />
<TextView
android:id="#+id/deviceName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:textColor="#color/white"
android:textSize="17sp"
tools:text="Solar Enviro SSL 2016" />
<TextView
android:id="#+id/connect"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:background="#drawable/rounded_red_view"
android:text="#string/connect"
android:paddingBottom="1dp"
android:paddingTop=".2dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textColor="#color/white"
android:textSize="17sp" />
</LinearLayout>
change this things..
used both wrap_content. i hope you also remove default action bar.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<TextView
android:id="#+id/scan_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="18dp"
android:gravity="center"
android:visibility="gone"
tools:visibility="visible" />
<android.support.v7.widget.RecyclerView
android:id="#+id/deviceListView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Instead of CoordinatorLayout use linear layout.
if u r a beginner start coding with linear layout. It is easy to understand.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

layout_below in relative layout won't show

i'm trying to make a layout_below the cardview in relative layout but it wont show up in my device where layout_above works. i dont know why it wont work. i think it should be work because it below the cardview. please help what did i miss or wrong.
this is my xml code
<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="#drawable/background_2"
tools:context=".ExchangeFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/saldo"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/holder" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="Will Stitch"
android:textSize="15dp"
android:textStyle="bold" />
</LinearLayout>
<android.support.v7.widget.CardView
android:id="#+id/saldo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Saldo"
android:textColor="#color/colorPrimary"
android:textSize="20dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/saldo"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="WillStitch#gmail.com"
android:textSize="10dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
please help why it like this
It is working but your ImageView take all the width and it don't have android:src attribute (so it show nothing) and you don't need the last LinearLayout :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/saldo"
android:orientation="vertical">
<!-- Useless Linear Layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="WillStitch#gmail.com"
android:textSize="10dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>

How to align imageview, and two text at center of screen android?

Hi I have parent layout as LinearLayout and I need to place an imageview at center and after that two textview one after another at center of screen. At bottom of the screen is an icon.
I placed everything but imageview and two textview are not aligning at center of screen. Here is layout.
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/bg"
android:orientation="vertical">
//this image and two textview, i need to place at center of screen
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/seat_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/on_logo"
android:layout_marginBottom="#dimen/dp_size20"
/>
<TextView
android:id="#+id/seat_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test1"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16dp"
android:gravity="center"/>
<TextView
android:id="#+id/another_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/dp_size10"
android:paddingBottom="#dimen/dp_size10"
android:text="TEst 2"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16dp"
android:gravity="center"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/dp_size10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<ImageView
android:id="#+id/on_boarding_circle_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:background="#drawable/circle_arrow" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
I really couldn't figure out what mistake I am doing in this design. ImageView, and two text are placing at top of screen and not in center of screen.
I have changed some dimensions and images, correct those and you are good to go.
try this..
<?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:background="#drawable/bg">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerInParent="true"
android:orientation="vertical">
<ImageView
android:id="#+id/seat_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#mipmap/ic_launcher"
android:layout_marginBottom="20dp" />
<TextView
android:id="#+id/seat_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test1"
android:textAllCaps="false"
android:textSize="16dp"
android:gravity="center"/>
<TextView
android:id="#+id/another_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/dp_size10"
android:paddingBottom="#dimen/dp_size10"
android:text="TEst 2"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16dp"
android:gravity="center"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="#dimen/dp_size10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<ImageView
android:id="#+id/on_boarding_circle_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:background="#mipmap/ic_launcher" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<?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:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<LinearLayout
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:id="#+id/seat_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
/>
<TextView
android:id="#+id/seat_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test1"
android:textAllCaps="false"
android:textColor="#color/Grey"
android:textSize="16dp"
android:gravity="center"/>
<TextView
android:id="#+id/another_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="TEst 2"
android:textAllCaps="false"
android:textSize="16dp"
android:gravity="center"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<ImageView
android:id="#+id/on_boarding_circle_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:background="#drawable/acircle" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
The problem is that you are using linear layout so it is aligning the layouts one after another.So you need to use relative layout and it will work
Try this code
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/bg"
android:orientation="vertical">
//this image and two textview, i need to place at center of screen
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/seat_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/on_logo"
android:layout_marginBottom="#dimen/dp_size20"
/>
<TextView
android:id="#+id/seat_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test1"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16dp"
android:gravity="center"/>
<TextView
android:id="#+id/another_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/dp_size10"
android:paddingBottom="#dimen/dp_size10"
android:text="TEst 2"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16dp"
android:gravity="center"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/dp_size10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<ImageView
android:id="#+id/on_boarding_circle_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:background="#drawable/circle_arrow" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
The RelativeLayout at the bottom is the problem. And add android:gravity="center" to your parent LinearLayout
Just add android:gravity="center" in your root LinearLayout and remove last RelativeLayout and see
cut the 'layout_gravity' and 'gravity' parameters from child LinearLayout and paste this to Parent LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/seat_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
Your code....
>

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>

How to align LinearLayout at bottom in a RelativeLayout?

I'm trying to get the LinearLayout to be aligned at the bottom of this RelativeLayout. I tried setting alignParentBottom="true", but then I can't even see the contents of the LinearLayout. Is there another way to accomplish what I need?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="90dp"
android:layout_height="200dp"
android:minHeight="200dp"
android:background="#color/colorPrimaryDark"
android:elevation="2dp"
android:gravity="center">
<TextView
android:id="#+id/textView_bookName"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:padding="10dp"
android:textSize="20dp"
android:textColor="#color/white"
/>
<TextView
android:id="#+id/textView_bookAuthor"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="1dp"
android:text="Author"
android:textSize="10dp"
android:textColor="#color/white"
android:layout_below="#+id/textView_bookName"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/textView_bookAuthor"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_download_book"
android:text="#string/download"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_read_book"
android:text="Read"
android:visibility="gone"/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/progressbar_book_download"
style="#android:style/Widget.ProgressBar.Horizontal"
android:progress="0"
android:visibility="gone"
/>
</LinearLayout>
</RelativeLayout>
Add to LinearLayout: android:layout_alignParentBottom="true"
eg.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_below="#+id/textView_bookAuthor">
[...]
<LinearLayout
android:layout_alignParentBottom="true"
android:layout_height="100dp"
android:layout_width="wrap_content">
</LineaLayout>
Try using a LinearLayout that contains both layouts and setting them an android:layout_weight and android:layout_height="0dp".
Don't forget to set the ratio between the weights to one you'd like and setting the container's android:orientation to vertical.
BTW, for textSize you better use sp and not dp...
Please try below xml which I have modified. It will solve the issue. I have removed the android:layout_below="#+id/textView_bookAuthor" and added android:layout_alignParentBottom="true".
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="90dp"
android:layout_height="200dp"
android:minHeight="200dp"
android:background="#color/colorPrimaryDark"
android:elevation="2dp"
android:gravity="center">
<TextView
android:id="#+id/textView_bookName"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:padding="10dp"
android:textSize="20dp"
/>
<TextView
android:id="#+id/textView_bookAuthor"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="1dp"
android:text="Author"
android:textSize="10dp"
android:layout_below="#+id/textView_bookName"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_download_book"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_read_book"
android:text="Read"
android:visibility="gone"/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/progressbar_book_download"
style="#android:style/Widget.ProgressBar.Horizontal"
android:progress="0"
android:visibility="gone"
/>
</LinearLayout>
</RelativeLayout>

Categories

Resources