hy!
I want to center my button horizontally, but this never work.
My Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/minage"
android:layout_alignParentLeft="true"
android:padding="5dp" />
<TextView
android:id="#+id/ml_minage_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp"/>
</RelativeLayout>
<SeekBar
android:id="#+id/ml_minage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100"
style="#style/NFFSeek"
android:progressDrawable="#drawable/myseekbar"
android:layout_margin="5dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/maxage"
android:padding="5dp"/>
<TextView
android:id="#+id/ml_maxage_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp" />
</RelativeLayout>
<SeekBar
android:id="#+id/ml_maxage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/NFFSeek"
android:progressDrawable="#drawable/myseekbar"
android:layout_margin="5dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/distance"
android:padding="5dp" />
<TextView
android:id="#+id/ml_distance_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp" />
</RelativeLayout>
<SeekBar
android:id="#+id/ml_distance"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/NFFSeek"
android:progressDrawable="#drawable/myseekbar"
android:layout_margin="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gender"
android:padding="5dp" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkedButton="#drawable/rbon" >
<RadioButton
android:id="#+id/ml_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:button="#drawable/rbselector"
android:checked="true"
android:drawablePadding="10dp"
android:text="#string/rb_female"
android:textColor="#000000"
android:paddingLeft="42dp" />
<RadioButton
android:id="#+id/ml_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rb_male"
android:button="#drawable/rbselector"
android:layout_margin="5dp"
android:textColor="#000000"
android:paddingLeft="42dp"
/>
</RadioGroup>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/ml_stbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#drawable/custom_button"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:padding="10dp"
android:text="Flirt"
android:textColor="#ffffff"
android:textSize="12pt"
android:typeface="serif" />
</RelativeLayout>
</LinearLayout>
this xml doesn't fit the button in the middle please help.
The problem is that the RelativeLayout does not span the width of the page, it's width is wrap_content. The button is centered in the RelativeLayout, but that layout is only as wide as the button, and is mashed up against the left side of the screen.
Make the inner RelativeLayout's width as match_parent.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/ml_stbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#drawable/custom_button"
android:layout_centerInParent="true"
android:gravity="center"
android:padding="10dp"
android:text="Flirt"
android:textColor="#ffffff"
android:textSize="12pt"
android:typeface="serif" />
</RelativeLayout>
This isn't speaking directly to your question, but your view hierarchy is too complicated. I suggest you replace all of the LinearLayout and RelativeLayout elements with a single RelativeLayout that spans the whole thing.
Related
I'm trying to create the following display, where the text scrolls and the other elements are fixed to the bottom of the screen:
However, it is appearing as follows, where the text doesn't scroll and it's pushing the elements off the screen.:
This is the layout I'm using:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ScrollView
android:id="#+id/scroller"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtTC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingLeft="20dp"
android:layout_alignParentLeft="true" />
</ScrollView>
<CheckBox
android:id="#+id/chkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="center"
android:text="Don't Show Again"
android:layout_below="#+id/scroller" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/chkBox"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_weight="1">
<ImageButton
android:id="#+id/imgCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingTop="0dip"
android:src="#drawable/stop"
android:paddingBottom="5dip"
android:paddingRight="5dip"
android:background="#drawable/common_button" />
<TextView
android:id="#+id/txtCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_below="#id/imgCancel"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="OK"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
What do I need to do to make the text scroll and the other elements fixed to the bottom of the screen?
Try replacing this xml code and apply images where you need
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#5555"
android:gravity="center"
android:orientation="vertical"
android:padding="25dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Terms and Conditions"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ScrollView
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<TextView
android:id="#+id/txtTC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingLeft="20dp"
android:textSize="20sp" />
</ScrollView>
<CheckBox
android:id="#+id/chkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/scroller"
android:layout_gravity="center_vertical"
android:text="Don't Show Again" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/chkBox"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_weight="1">
<ImageButton
android:id="#+id/imgCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingTop="0dip"
android:paddingBottom="5dip"
android:paddingRight="5dip" />
<TextView
android:id="#+id/txtCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_below="#id/imgCancel"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="OK"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
You should add the ScrollView Containing the TextView inside a Layout(Linear would do). I hope it helps
I am trying to create a Row layout to use in my ListView,
but when the text is too long, it pushes the right hand side ImageButton off the screen.
I want the text to just continue on the next line without interfering with the ImageButton-
This is the layout I have so far, I tried adding weight properties to set how much space could be use but I couldn't get it to work.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/ImageButton"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:drawableTop="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Thank You.
No matter what lenght if text, first and last image will be of width 50dp occupied, rest space for text.
<LinearLayout
android:layout_width="50dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:layout_width="50dp"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/ImageButton"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:drawableTop="#drawable/ic_launcher" />
</LinearLayout>
You're using too many LinearLayouts, and also you're not defining any constrain for your views space.
Try this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/ImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:drawableTop="#drawable/ic_launcher" />
<LinearLayout
android:id="#+id/LinearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/ImageButton"
android:layout_toRightOf="#id/ImageView"
android:orientation="vertical" >
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</RelativeLayout>
I am unable to get the below shown layout..can anyone let me know how to achieve this layout ?
This is what I have but unable to get the specified layout.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="left"
android:layout_weight="1">
<ImageView
android:id="#+id/someimage"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#88FF0000" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right">
<TextView
android:id="#+id/txtview1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtview2"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="right"
android:layout_below="#id/txtview1"/>
<TextView
android:id="#+id/txtview3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:textColor="#003399"
android:textSize="19sp"
android:textStyle="bold"
android:layout_below="#id/txtview2"/>
</RelativeLayout>
</LinearLayout>
I want to get this as final layout:
You can use a single RelativeLayout
You can remove the unwanted RelativeLayout with black background. (Just to differentiate i added another relative layout with black background)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="15dp"
android:text="TextView" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:src="#drawable/ic_launcher" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:layout_below="#+id/imageView1" >
</RelativeLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="16dp"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="54dp"
android:layout_marginTop="14dp"
android:text="TextView" />
</RelativeLayout>
Edit:
You can also center the text in TextView and use match_parent for the layout width and remove the unwanted realtive layout. Notice the change android:layout_toRightOf="#+id/imageView1" in the below code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView2"
android:layout_toRightOf="#+id/imageView1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="15dp"
android:text="TextView" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView3"
android:layout_toRightOf="#+id/imageView1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="15dp"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_toRightOf="#+id/imageView1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:text="TextView" />
</RelativeLayout>
snap
You need to set the layout_width of all TextViews to fill_parent.
Note that your code should not even compile because the layout_width attribute is mandatory, and you don't specify it for the second TextView, and it also does not have a style attribute where it might be specified.
The below hierarchy can also do what you want:
Linear-Horizontal
Linear-Vertical
imageview
Linear-Horizontal
textview
textview
textview
What about a vertical linear layout where you put the image view in. Also put a horizontal linear layout in, where you place the textviews. Set the vertical height to wrap content and the horizontal to match parent.
Let me know if this works for you
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="left"
android:layout_weight="1">
<ImageView
android:id="#+id/someimage"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#88FF0000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right" >
<TextView
android:id="#+id/txtview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="TextView1"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtview1"
android:focusable="false"
android:gravity="center"
android:text="TextView2" />
<TextView
android:id="#+id/txtview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="19sp"
android:textStyle="bold"
android:gravity="center"
android:text="Textview 3"
android:layout_below="#id/txtview2"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
i am implementing one data enter screen with many fields.so that i am using scrolling view in my layout.But i want to draw OK button always.but i am unable to lock the some part of the screen.
i need secreen as:
but i am getting picture as either
or
i am adding my layout code below(as shown in last pic) plesae help me .
<?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" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#2E9AFE" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Present Details"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColorHint="#350924"
android:textStyle="bold" />
<TextView
android:id="#+id/tvtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Present Location"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#350924"
android:textStyle="bold" />
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<EditText
android:id="#+id/etPreLoc1"
android:layout_width="fill_parent"
android:layout_height="120dp"
android:layout_gravity="center"
android:ems="10"
android:hint="Where are u now?"
android:inputType="textPostalAddress" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/etPreLoc1"
android:layout_gravity="center"
android:text="Coming By"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#350924"
android:textStyle="bold" />
<EditText
android:id="#+id/mmsComing"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="car/auto/other" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Vehicle details"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#350924"
android:textStyle="bold" />
<EditText
android:id="#+id/etDriver"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="Driver name/vehicle no"
android:inputType="textPersonName" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Expected time to reach by:"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#350924"
android:textStyle="bold" />
<TimePicker
android:id="#+id/timePicker2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_weight="75" />
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/mmsOk"
android:layout_width="fill_parent"
android:layout_height="64dp"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="25"
android:background="#drawable/blackbutton"
android:text="OK"
android:textColor="#android:color/white"
android:textSize="32dp"
android:textStyle="bold" />
</LinearLayout>
You can do that with a RelativeLayout like that. Just put all you views in the linearlayout inside the scrollview.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</RelativeLayout>
Change scrollview height to 0dp and give weight as 1.
Change button layout gravity to bottom instead of center.
I just want to add an image beside the Spinner in my layout. I tried align:layout_gravity = "right" for the image, but this moved the image to the right side in the layout and below the Spinner present in the same layout. What I want is for the image to be displayed exactly besides the Spinner. Below is the xml layout file:
<LinearLayout
android:id="#+id/topLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:background="#color/headingBgColor"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/yourName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Group"
android:textColor="#color/black" />
</ImageView>
</LinearLayout>
<LinearLayout
android:id="#+id/bottomLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal"
android:padding="5sp" >
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tasks"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Messages"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Groups"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notes"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MyProfile"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/centerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/topLayout"
android:orientation="vertical"
android:padding="10sp" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:paddingTop="20dip" />
<ImageView
android:id="#+id/imageButton"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_gravity="right"
android:src="#drawable/contacts" />
<LinearLayout
android:id="#+id/centerLqayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10sp" >
<CheckBox
android:id="#+id/sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SMS"
android:textColor="#color/black" />
<CheckBox
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textColor="#color/black" />
</LinearLayout>
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="140dp"
android:gravity="top"
android:inputType="textPostalAddress" >
<requestFocus />
</EditText>
<Button
android:id="#+id/deleteBlockLog1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Send"
android:textSize="#dimen/font_size_15" />
</LinearLayout>
LinearLayout with orientation set to vertical will put the child views one below other. You have two options:
You either wrap the Spinner and the ImageView in another LinearLayout with orientation set to horizontal so the two views end up on the same line.
Example:
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal">
<Spinner
android:id="#+id/spinner1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:paddingTop="20dip" />
<ImageView
android:id="#+id/imageButton"
android:layout_width="100dp"
android:layout_height="70dp"
android:src="#drawable/contacts" />
</LinearLayout>
You use a layout that allows the children to be placed relative to others(like a RelativeLayout) instead of the parent LinearLayout with the id centerLayout.