Positioning ScrollView on screen - android

I would like to position a ScrollView at a certain part of screen independently of the screen size and resolution. E.g. I would like it to take up the bottom 30% of the space. Above this ScrollView I want to have an image and empty space.
I have tried that by putting all the views into a linear layout and assigning weights, but that doesn't seem to work. Any ideas about the solution?
The layout I have at the moment:
<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">
<ImageView
android:id="#+id/appLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/logo"/>
<ProgressBar
android:id="#+id/progressbar"
android:indeterminate="true"
android:layout_width="50dp"
android:layout_height="50dp"
style="?android:attr/progressBarStyle"
android:indeterminateBehavior="cycle"
android:layout_below="#id/appLogo"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical|center_horizontal"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/appLogo">
<LinearLayout
android:id="#+id/startLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
</LinearLayout>
</ScrollView>
</RelativeLayout>
Inside the ScrollView I have a LinearLayout, which I use to put in TextView and ImageView elements programaticaly.
What I want to achieve is that no no matter the screen size, there would always be visible a maximum of 3 child elements.
What I tried to do:
<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="#android:color/black">"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/appLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_weight="70"
android:src="#drawable/logo"/>
<ProgressBar
android:id="#+id/progressbar"
android:indeterminate="true"
android:layout_width="50dp"
android:layout_height="50dp"
style="?android:attr/progressBarStyle"
android:indeterminateBehavior="cycle"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical|center_horizontal"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="30">
<LinearLayout
android:id="#+id/startLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
But the ScrollView only end ups taking even more space and the image on top gets smaller.

I added a linearlayout for imageview and progress bar and gave it 0dp height and 70 weight.
Also notice that parent linearlayout has a weightsum set to 100.
<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="#android:color/black">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="70"
android:orientation="vertical">
<ImageView
android:id="#+id/appLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/logo"/>
<ProgressBar
android:id="#+id/progressbar"
android:indeterminate="true"
android:layout_width="50dp"
android:layout_height="50dp"
style="?android:attr/progressBarStyle"
android:indeterminateBehavior="cycle"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical|center_horizontal"/>
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="30">
<LinearLayout
android:id="#+id/startLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>

// try this and let me know if any problem i'm done your requirement with linear 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"
android:orientation="vertical"
android:gravity="center_horizontal">
<ImageView
android:id="#+id/appLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:layout_weight="0.70">
<ProgressBar
android:id="#+id/progressbar"
android:indeterminate="true"
android:layout_width="50dp"
android:layout_height="50dp"
style="?android:attr/progressBarStyle"
android:indeterminateBehavior="cycle"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.30">
<LinearLayout
android:id="#+id/startLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"/>
</ScrollView>
</LinearLayout>

Related

Two RelativeLayouts sharing screen width

I have two RelativeLayouts. Each of them has some content which is unknown width. I cant use LinearLayout and set layout_weight, because one of this RelativeLayout has android:layout_alignParentEnd="true" and I don't know if it will be enough for children in terms of width.
Code:
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="80dp"
android:paddingTop="#dimen/padding_small"
android:paddingBottom="#dimen/padding_small"
android:paddingStart="#dimen/padding_medium"
android:paddingEnd="#dimen/padding_medium"
android:background="#color/grey">
<RelativeLayout
android:id="#+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toStartOf="#id/secondLayout">
</RelativeLayout>
<RelativeLayout
android:id="#+id/secondLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true">
</RelativeLayout>
</RelativeLayout>
Expected result:
Reality:
Just give some specific width to the second layout instead of wrap_content like this I have given 100dp here
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="80dp"
android:paddingTop="#dimen/padding_small"
android:paddingBottom="#dimen/padding_small"
android:paddingStart="#dimen/padding_medium"
android:paddingEnd="#dimen/padding_medium"
android:background="#color/grey">
<RelativeLayout
android:id="#+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toStartOf="#id/secondLayout">
</RelativeLayout>
<RelativeLayout
android:id="#+id/secondLayout"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true">
</RelativeLayout>
</RelativeLayout>
If you want to make layout what you expect, there are many way.
for example, (only use LinearLayout and RelativeLayout)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#color/colorPrimary"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:layout_weight="1"
android:id="#+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toStartOf="#id/secondLayout"
android:background="#color/colorAccent" />
<TextView
android:layout_width="match_parent"
android:text="header"
android:background="#color/colorWhite"
android:layout_height="wrap_content"/>
</LinearLayout>
<RelativeLayout
android:id="#+id/secondLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_weight="2"
android:background="#color/colorPrimaryDark" />
</LinearLayout>
this xml can make this.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#858585"
android:paddingStart="8dp"
android:paddingTop="4dp"
android:paddingEnd="8dp"
android:paddingBottom="4dp">
<RelativeLayout
android:id="#+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66b35f"
android:layout_toStartOf="#id/secondLayout"/>
<RelativeLayout
android:id="#+id/secondLayout"
android:minWidth="120dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#6e89c2"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
You should use the parameter "android:minWidth="Xdp"
Then it looks like above.

ImageView displays above the ListView

I have a layout which consists of a ListView and an Image. I want to place the Image above Listview (in top left corner), but on running the app only Listview is visible and Image goes behind the Listview.
I want to show image instead of first item of the list. Any suggestions?
Below is the layout file:
<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="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#android:color/background_light"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="100">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/back"
android:id="#+id/back_button"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:focusable="true"
/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoice">
</ListView>
</FrameLayout>
</RelativeLayout>
</LinearLayout>
<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="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#android:color/background_light"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/back"
android:id="#+id/back_button"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:focusable="true"
/>
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoice">
</ListView>
</LinearLayout>
<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="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#android:color/background_light"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="100">
<FrameLayout
android:id="#+id/frameLayoutImagevIew"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/back"
android:id="#+id/back_button"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:focusable="true"
/>
</FrameLayout>
<FrameLayout
android:layout_below="#id/frameLayoutImagevIew"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoice">
</ListView>
</FrameLayout>
</RelativeLayout>
</LinearLayout>
Try to set an elevation value in the ImageView. For example: android:elevation="5dp". This should solve your problem. Hope it helps.
You can use headerview to add the image at the top like
listview.addHeaderView(view);// view which contains that image
Try this.

LinearLayout Beneath LinearLayout full width?

I have an ImageView and a TextView that are the only items in my Android UI. Currently the TextView is in the same LinearLayout as the ImageView, so the text sometimes runs to 2 lines. I want to get the text on its own line, with the full width of the parent element so it will be the whole width of the screen. So far everything I've tried moves the ImageView outside the window or makes it very small.
<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="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:weightSum="4"
android:gravity="center"
tools:context=".MainActivity"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:orientation="vertical"
android:layout_weight="2"
android:gravity="center_vertical"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/activity_main_imageview_gototags"
android:src="#drawable/img_main_gototags"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:onClick="imageViewGoToTagsOnClickOnClick"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/activity_main_textview_tagline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/activity_main_textview_tagline"
android:textColor="#color/dark_blue"
android:gravity="center"
android:textSize="30sp"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</LinearLayout>
May be this is what you want
<?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="match_parent"
android:orientation="vertical"
android:gravity="center"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="#+id/activity_main_imageview_gototags"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:onClick="imageViewGoToTagsOnClickOnClick"
android:scaleType="centerCrop"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" />
</LinearLayout>
<TextView
android:id="#+id/activity_main_textview_tagline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:singleLine="true"
android:gravity="center"
android:text="lfhjdhkjfhkjdhkjfhkdhkjfhdkshfkhskahdfkjdhkhkjfhdk"
android:textColor="#android:color/holo_blue_bright"
android:textSize="30sp" />
</LinearLayout>
I hope it helps.let me know if it did not.
Don't give the parent(LinearLayout) of your ImageView a width of 0dp make it match_parent instead and the same for your TextView also there's a property on text views android:maxLines that corresponds to how many lines at max can it go to, set it to 1 and if you need truncation you can also use android:ellipsize on the text view.

vertical centering one view inside a LinearLayout with two views

i would like to force gauge to be centered vertically above llInner...
i just don't seem to be able
instead of llTop using all the available space it is llInner doing it.
thank you
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llTop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#ff0000">
<eu.sextante.speedlimit.Views.GaugeView
android:id="#+id/gauge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<LinearLayout
android:id="#+id/llInner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="bottom|right"
android:gravity="bottom|right"
android:background="#00ff00">
<eu.sextante.speedlimit.Views.LimitView
android:id="#+id/limit"
android:layout_width="wrap_content"
android:layout_height="60dip"
android:background="#0000ff"
android:maxHeight="60dip"
android:maxWidth="60dip"/>
</LinearLayout>
You should use Relative Layout as main layout like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/llInner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="bottom|right"
android:background="#00ff00"
android:gravity="bottom|right"
android:orientation="horizontal" >
<eu.sextante.speedlimit.Views.LimitView
android:id="#+id/limit"
android:layout_width="wrap_content"
android:layout_height="60dip"
android:background="#0000ff"
android:maxHeight="60dip"
android:maxWidth="60dip" />
</LinearLayout>
<your.gaugeview
android:id="#+id/gauge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="dfdg" />
</RelativeLayout>
Hope it helps you.

Android Relative Layout with sticky footer

I'm relatively new to Android development and I'm having a hard time putting together a certain interface. I've looked through many similar questions but none of them give me the answer i'm looking for.
I want to put together an XML interface like the following:
I want a LinearLayout that acts like a sticky footer that will contain two Buttons. This part will always align to the bottom and and will always be 60dp high. The RelativeLayout would then be on top of the footer, but it's height should scale depending on the screen size.
I've tried the following:
<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="match_parent"
android:orientation="vertical"
tools:context=".DartboardActivity">
<RelativeLayout
android:id="#+id/game_layout"
android:layout_width="match_parent"
android:layout_height="506dp"
android:background="#drawable/background"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<ImageView
android:id="#+id/Dartboard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#string/desc_dartboard"
android:src="#drawable/dartboard" />
<hhs.week3.dartboard.VerticalSeekBar
android:id="#+id/seekBarVertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:thumb="#drawable/thumbhorizontal"
android:layout_marginBottom="40dp" />
<SeekBar
android:id="#+id/seekBarHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:thumb="#drawable/thumbhorizontal" />
</RelativeLayout>
<LinearLayout
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#333">
<Button
android:id="#+id/fire"
style="#style/button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:text="#string/fire" />
<Button
android:id="#+id/settings"
style="#style/button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:text="#string/settings" />
</LinearLayout>
</LinearLayout>
I got it working half decently, but it requires me to give the RelativeLayout bit a fixed height, making it look right on my phone, but not on others.
How do I best approach this?
Use the LinearLayout layout_weight mechanism to assign all remaining space to your RelativeLayout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
... />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
... />
</LinearLayout>
Try following 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:orientation="vertical"
tools:context=".DartboardActivity" >
<RelativeLayout
android:id="#+id/game_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/buttons"
android:layout_alignParentTop="true"
android:background="#drawable/ic_launcher"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
</RelativeLayout>
<LinearLayout
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="#333"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
I removed LinearLayout and replaced with RelativeLayout. This will allow you to set your LinearLayout stick to bottom.
I was able to achieve the same result by using below code. Basically, the parent layout is one Linear layout and the first child element is a scrollview so it can squeeze its content when the keyboard is shown. Also note the use of the android:layout_height="0dp" and android:layout_weight="1" used with the scrollview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/wrap"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/wrap2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
</LinearLayout>
</ScrollView>
<FrameLayout
android:id="#+id/buttonsPanel"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#333" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="action buttons" />
</FrameLayout>
</LinearLayout>
Try this
<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="match_parent"
android:orientation="vertical"
tools:context=".DartboardActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1"
android:background="#drawable/background"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<ImageView
android:id="#+id/Dartboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/desc_dartboard"
android:src="#drawable/dartboard"
android:adjustViewBounds="true"/>
<hhs.week3.dartboard.VerticalSeekBar
android:layout_marginTop="10dp"
android:id="#+id/seekBarVertical"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:thumb="#drawable/thumbhorizontal"/>
<SeekBar
android:id="#+id/seekBarHorizontal"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:thumb="#drawable/thumbhorizontal" />
</LinearLayout>
<LinearLayout
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#333333">
<Button
android:id="#+id/fire"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="#string/fire"/>
<Button
android:id="#+id/settings"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="#string/settings"/>
</LinearLayout>
</LinearLayout>

Categories

Resources