LinearLayout Beneath LinearLayout full width? - android

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.

Related

two textviews in two layouts

I want to have two relative layouts side-by-side vertically and put one text view in each layout. I want each layout to take up half of the screen (hence I used android:layout_weight="50". Here is the xml code for the main activity:
<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="helloworld3.myapplication.MainActivity">
<RelativeLayout
android:id="#+id/view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
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="helloworld3.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World 1!" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
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:layout_below="#id/view1"
tools:context="helloworld3.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World 2!" />
</RelativeLayout>
</RelativeLayout>
But the result displays only the first text view "Hello world 1!" and it does not display the second one, Hello world 2! Can anyone help?
Just add weight sum in parent layout and change its from Relative to Linear
layout . Also In Child layout like two relative one add layout height to
0dp below is updated code
<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: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="100">
<RelativeLayout
android:id="#+id/view1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World 1!" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#id/view1"
android:layout_weight="50"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World 2!" />
</RelativeLayout>
</LinearLayout>
If you want 2 TextViews one of top of another, taking 1/2 the screen each, just use a LinearLayout with vertical orientation:
<?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">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Text 1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Text 2"/>
</LinearLayout>
If you do not want the TextViews to be 1/2 the height, you can wrap them in a FrameLayout:
<?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">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text 1" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text 2" />
</FrameLayout>
</LinearLayout>
Why don't you just use a horizontal linearlayout and adjust the weight to .5 for each textview and set the gravity of the textview to where you want it
Your RelativeLayout's are both set to match_parent for layout_width and layout_height
You need to set one of these to 0dp for layout_weight to have any effect. The parent should probably be changed to a LinearLayout as well. By the way layout_weight value shouldn't matter as long as they are both equal: see below
<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="horizontal"
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="helloworld3.myapplication.MainActivity">
<RelativeLayout
android:id="#+id/view1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
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="helloworld3.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World 1!" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
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:layout_below="#id/view1"
tools:context="helloworld3.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World 2!" />
</RelativeLayout>
if you want to divide the screen half-half. you dont have to set layout_weight to 50. just set layout_height(as you want to vertically divide the screen) to 0dp, then android will do what you want without considering the RelativeLayout's height. so it could be like this:
<?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"
tools:context="demo.drawable.propertyanimationdemo.HalfLayoutActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/holo_orange_light"></RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/holo_blue_dark"></RelativeLayout>
</LinearLayout>
use linear layout (Horizontal)
<LinearLayout
android:layout_width="match_parent"
android:weightSum="2"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0sp"
android:layout_weight="1"
android:text="Demo 1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0sp"
android:layout_weight="1"
android:text="Demo 2"/></LinearLayout>
First off all i would suggest you to use Linear Layout for this purpose. the linear layout can easily divide the screen based on the weights given to it.
Below is a sample that will suit your problem.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="helloworld3.myapplication.MainActivity">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="view 1"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="view 2"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</LinearLayout>
Apply this to your own layout and you will get what you want. do tell if it worked for you. Do accept the answer as correct answer.

Android Layout width of 50%

I am using a relative layout to create an Android UI in XML. The layout is centered around an ImageView and TextView. I need these 2 elements to lay above and below eachother. I want to make it so that these 2 elements take up 50% of the whole width. I tried a LinearLayout with an android:layout_weight=".5" but I couldnt get it it center both horizontally and vertically. Here is the relative layout that I have, I want it to look like this but with the image taking up 50% of the width, with 25% of whitespace on either side. I also need to do it in XML. Any guidance is appreciated.
<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">
<ImageView
android:id="#+id/activity_main_imageview_logo"
android:src="#drawable/img_main_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="centerCrop"
android:paddingBottom="12dp"
android:onClick="imageViewGTTOnClick"
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="28sp"
android:layout_below="#+id/activity_main_imageview_logo"
android:layout_centerHorizontal="true" />
</RelativeLayout>
This should do the trick:
<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_logo"
android:src="#drawable/img_main_logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:paddingBottom="12dp"
android:onClick="imageViewGTTOnClick"
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="28sp"/>
</LinearLayout>
</LinearLayout>

nested linearlayout is not working properly

i want edittext and send button in one row but image in other row ...but using this code edit text,send button,and image are displaying in one row..can you please tell me what should i do to display image in other row
<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:orientation="horizontal"
tools:context=".MainActivity" >
<EditText
android:id="#+id/edit_message "
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:onClick="sendMessage" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo" />
</LinearLayout>
</LinearLayout>
You could wrap your EditText and Button in a LinearLayout
<LinearLayout
android:orientation="vertical"
...>
<LinearLayout
...>
<EditText
.../>
<Button
.../>
</LinearLayout>
<ImageView
.../>
</LinearLayout>
But I would probably use a RelativeLayout
<RelativeLayout
...>
<EditText
android:id="#+id/et"
.../>
<Button
android:layout_toRightOf="#id/et"
.../>
<ImageView
android:layout_below="#id/et"
.../>
</RelativeLayout>
But that also depends on exactly where you want things.
<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:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/edit_message "
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:onClick="sendMessage" />
</LinearLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo" />
</LinearLayout>
To get the ImageView to display in a row beneath the EditText and Button, you need to set the orientation for your outer LinearLayout to be Vertical and then wrap the EditText and Button in a Linear layout with a horizontal orientation.

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>

stick LinearLayour ( horizontal ) to the buttom without any space

Sorry, i've completed my question very much, so I reasked that and deleted prev post...
I'm using LinearLayout ( with 4 ImageButtons in a raw ) in a RelativeLayout in my project and I have used android:layout_alignParentBottom="true" for it ( linear ) to stick to the buttom of RelativeLayout, but my problem is the space between LinearLayout's ImageButtons and the corners of the screen. I want to remove them to make my ImageButtons be like a menu bar on the bottom of the screen. Is it possible for anyone to help me please ? THANK YOU ! :)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android: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=".HomeActivity">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="TXT"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="4" >
<ImageButton
android:id="#+id/calibrate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/1" />
<ImageButton
android:id="#+id/chart"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/2" />
<ImageButton
android:id="#+id/guidance"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/3" />
<ImageButton
android:id="#+id/info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable4" />
</LinearLayout>
</RelativeLayout>
and the result is something like this : Picture http://uploadtak.com/images/c6645_1311.png!
1
Remove the padding on your RelativeLAyout
From:
<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=".HomeActivity">
To:
<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" >

Categories

Resources