I'm making a layout:
Here is a 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="wrap_content"
android:background="#373c5c"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout android:id="#+id/list_offer_item_container"
android:layout_marginTop="15dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/shape"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="#+id/imgcreditcompany"
android:layout_width="36dp"
android:layout_marginRight="4dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:contentDescription="#string/app_name"
android:layout_height="36dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="start"
android:orientation="vertical" >
<TextView
android:id="#+id/txtname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="1dp"
android:textColor="#48899f"
android:textSize="#dimen/textsizeearncredit_title"
android:text="Name"
android:textAllCaps="false"
android:textStyle="normal|bold" />
<TextView
android:id="#+id/txtdesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="1dp"
android:maxLines="1"
android:textColor="#80869c"
android:textSize="#dimen/textsizeearncredit_desc"
android:text="This is a description of the offer and this is just a demo to show off 3 lines stacking correctly on top of each other"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="20dp"
android:gravity="end"
android:layout_gravity="center_vertical">
<TextView android:id="#+id/list_offer_badge_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/list_offer_item_container"
android:textColor="#color/md_amber_700"
android:textSize="12sp"
android:visibility="gone"
android:text=""/>
</LinearLayout>
<ImageView
android:id="#+id/nextArrow"
android:layout_alignParentRight="true"
android:tint="#color/md_grey_300"
android:rotation="180"
android:layout_width="32dp"
android:visibility="gone"
android:layout_marginRight="16dp"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_height="32dp"
android:contentDescription="#string/app_name"
android:padding="#dimen/two" />
</LinearLayout>
</RelativeLayout>
How to add an text above the 'button style' linear layout?
I want for example "Hello dear user! Check it below".
Where put textview, where add more layout or whatever?
It is very simple!
You have to add TextView, with id (text, for example) and, in your LinearLayout you need to add line android:layout_below="#+id/text". Optional, you can specify attribute android:layout_alignParentTop="true" in TextView.
Just use code below:
<?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="wrap_content"
android:background="#373c5c"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/text"
android:text="Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
/>
<LinearLayout android:id="#+id/list_offer_item_container"
android:layout_below="#+id/text"
android:layout_marginTop="15dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/shape"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="#+id/imgcreditcompany"
android:layout_width="36dp"
android:layout_marginRight="4dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:contentDescription="#string/app_name"
android:layout_height="36dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="start"
android:orientation="vertical" >
<TextView
android:id="#+id/txtname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="1dp"
android:textColor="#48899f"
android:textSize="#dimen/textsizeearncredit_title"
android:text="Name"
android:textAllCaps="false"
android:textStyle="normal|bold" />
<TextView
android:id="#+id/txtdesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="1dp"
android:maxLines="1"
android:textColor="#80869c"
android:textSize="#dimen/textsizeearncredit_desc"
android:text="This is a description of the offer and this is just a demo to show off 3 lines stacking correctly on top of each other"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="20dp"
android:gravity="end"
android:layout_gravity="center_vertical">
<TextView android:id="#+id/list_offer_badge_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/list_offer_item_container"
android:textColor="#color/md_amber_700"
android:textSize="12sp"
android:visibility="gone"
android:text=""/>
</LinearLayout>
<ImageView
android:id="#+id/nextArrow"
android:layout_alignParentRight="true"
android:tint="#color/md_grey_300"
android:rotation="180"
android:layout_width="32dp"
android:visibility="gone"
android:layout_marginRight="16dp"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_height="32dp"
android:contentDescription="#string/app_name"
android:padding="#dimen/two" />
</LinearLayout>
</RelativeLayout>
Above
<LinearLayout android:id="#+id/list_offer_item_container"
put your TextView or whatever you want. So something like
<TextView android:id="#+id/myTV"
// other attributes />
Then in
<LinearLayout android:id="#+id/list_offer_item_container"
add android:layout_below="#id/myTV"
By default, RelativeLayout puts it's elements at the top-left until you specify otherwise. So adding this will put your LinearLayout below the TextView.
I think the confusion is on how RelativeLayout and LinearLayout work. You have orientation in your RelativeLayout which does nothing. RelativeLayout puts it's elements in the order you tell it by the attributes such as layout_below and layout_above. LinearLayout, however, adds them in the order in which they show in the xml file which is why orientation matters in LinearLayout but not RelativeLayout.
You'll want to look at RelativeLayout.LayoutParams and other parts of the documentation to better understand how the layouts work and which is best in your specific cases.
Related
I am trying to set my admob banner on bottom of the screen but it's not showing. I have tried all possible way to set it as bottom but I am unable to set it...its going down side of expandable list view.
My XML is like below...let me know if someone can help me to sort out issue.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e7e7e7"
android:gravity="center"
android:orientation="vertical"
android:weightSum="1">
<include
layout="#layout/top_points_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/five">
</View>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="#dimen/laytop_imgwidthheight"
android:layout_height="#dimen/laytop_imgwidthheight"
android:contentDescription="#string/app_name"
android:src="#drawable/app_icon"
android:visibility="gone" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:gravity="left"
android:padding="#dimen/five"
android:text="Country of Purchase"
android:textColor="#color/Gray"
android:textSize="18sp"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/layout_country_selection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="5dp"
android:background="#drawable/list_item_background"
android:orientation="horizontal"
android:padding="6dp">
<com.commonutility.RoundImageView
android:id="#+id/imageView_country_logo"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="4dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/country_default_logo"
android:visibility="visible" />
<TextView
android:id="#+id/textView_country_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_toRightOf="#+id/imageView_country_logo"
android:padding="5dp"
android:text="Select Your Country"
android:textColor="#color/Blue"
android:textSize="19sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="5dp"
android:padding="3dp"
android:src="#drawable/dropdown" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="2">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/five"
android:layout_weight="1"
android:gravity="right"
android:paddingBottom="#dimen/five"
android:paddingTop="#dimen/five"
android:text="Country"
android:textColor="#fe4080"
android:textSize="#dimen/rewards_countrytextsize"
android:textStyle="bold" />
<TextView
android:id="#+id/txtcountry"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="left"
android:paddingBottom="#dimen/five"
android:paddingTop="#dimen/five"
android:text="USA"
android:textColor="#color/material_color_primary_dark"
android:textSize="#dimen/rewards_countrytextsize"
android:textStyle="bold" />
</LinearLayout>
<ExpandableListView
android:id="#+id/lvExp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/list_item_background"
android:cacheColorHint="#android:color/transparent"
android:divider="#color/md_white_1000"
android:dividerHeight="0dp"
android:groupIndicator="#null"
android:scrollbars="none" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:clickable="false"
android:nestedScrollingEnabled="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/banner_home_footer">
</com.google.android.gms.ads.AdView>
</LinearLayout>
Let me know what is wrong in this.
Thanks :)
android:layout_alignParentBottom="true"
works only in RelativeLayout, but it's inside a LinearLayout.
You could change the root layout to RelativeLayout and wrap everything but your AdView inside another LinearLayout (or better handle the behaviour of the other views as expected inside a RelativeLayout to avoid deep layouts).
So I have 2 textviews, one above the other, but when the second text view is populated the cut is cut off at the bottom. The textview, titled header_subtitle has the issue in question
Clearly Im missing something obvious, but dont know what.
[Issue]1
Here is the code:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="#layout/search_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
<RelativeLayout
android:id="#+id/container_results"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:visibility="gone">
<LinearLayout
android:id="#+id/container_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="#dimen/product_results_header_height"
android:orientation="vertical"
android:padding="?marginNormal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<FeatureTextView
android:id="#+id/header_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textAppearance="?taTitleXL" />
<FeatureTextView
android:id="#+id/header_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:layout_gravity="fill"
android:textAppearance="?taTitleXL"
android:padding="1sp"
android:visibility="gone"/>
</LinearLayout>
<Spinner
android:id="#+id/sort_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="?marginNormal" />
<FeatureButton
android:id="#+id/refine_btn"
style="?buttonTertiary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="?marginNormal"
android:text="#string/product_results_refine" />
</LinearLayout>
<SimpleFlowLayout
android:id="#+id/category_links"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?marginSmall"
android:horizontalSpacing="?marginTiny"
android:maxLines="2" />
</LinearLayout>
<include
android:id="#+id/divider_horizontal"
layout="#layout/divider_horizontal"
android:layout_width="match_parent"
android:layout_height="#dimen/divider_size"
android:layout_below="#+id/container_header" />
<FeatureTextView
android:id="#+id/browse_no_results"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/divider_horizontal"
android:layout_margin="?marginNormal"
android:text="#string/product_results_no_results"
android:textAppearance="?taTitleM"
android:visibility="gone" />
<GridView
android:id="#+id/product_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/divider_horizontal"
android:numColumns="#integer/product_grid_cols"
android:overScrollMode="#null"
android:stretchMode="columnWidth" />
<include
android:id="#+id/progress_footer"
layout="#layout/loading"
android:layout_width="#dimen/progress_view_height"
android:layout_height="#dimen/progress_view_height"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
<NoFilteredResultsView
android:id="#+id/noFilteredResults"
android:layout_below="#id/divider_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<include
android:id="#+id/coach_mark"
layout="#layout/view_coach_mark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginEnd="#dimen/coach_mark_margin_end"
android:layout_marginTop="#dimen/coach_mark_margin_top" />
</RelativeLayout>
</FrameLayout>
One of your LinearLayouts has height set to fill_parent. change it to wrap_content.
Also, remove the min_height attribute. Yout have two text fields in there, so it looks like you're totally OK with the second getting cut off.
It's kind of hard to tell what you're going for, but see if that helps.
i know it's so late, but this is work like charm for me. add this code to your textview
android:ellipsize="marquee"
android:layout_weight="1"
Merging two TextView tags into one solved my issue:
<LinearLayout
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:gravity="center_horizontal"
android:id="#+id/app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="2dp"
android:text="© 1997 - 2020 "
android:textColor="#color/black"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/text_digicollect"
android:text="Onetime"
android:textColor="#color/black"
android:layout_marginStart="4dp"/>
</LinearLayout>
Changing to:
<LinearLayout
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:gravity="center_horizontal"
android:id="#+id/app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="2dp"
android:text="© 1997 - 2020 OneTime"
android:textColor="#color/black"
android:textSize="12sp" />
</LinearLayout>
I have a layout as follows. The problem I have is that if the TextView of friend_name is very long it “pushes” down the rest and they overlap/cover last ViewStub of friend_last_msg
How can I make the last ViewStub to also “adjust” on this “lowering of the other widgets?
Or else how could I make that last view stub to be inside the LinearLayout and displayed to the left side and down?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
>
<ImageView
android:id="#+id/friend_img”
android:layout_width="#dimen/friend_big”
android:layout_height="#dimen/friend_big”
android:layout_alignParentLeft="true"
android:scaleType="centerCrop"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="8dp"
android:layout_toRightOf="#+id/friend_img"
>
<TextView
android:id="#+id/friend_name”
android:layout_toRightOf="#id/friend_img"
android:layout_marginBottom="#dimen/layout_small_padding"
android:includeFontPadding="false"
android:paddingBottom="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:ellipsize="end"
android:gravity="top"
/>
<ViewStub
android:id="#+id/friend_sign”
android:inflatedId="#+id/friend_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="#layout/friend_sign_layout”/>
<TextView
android:id="#+id/friend_contact”
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:padding="5dp"
/>
</LinearLayout>
<ViewStub
android:id="#+id/friend_last_msg”
android:inflatedId="#+id/friend_last_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout="#layout/friend_last_msg"/>
</RelativeLayout>
First of all enter the closing commas right like this then enter the android:layout_height and android:layout_width values according to your needs.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
>
<ImageView
android:id="#+id/friend_img[**"**]
android:layout_width="#dimen/friend_big[**"**]
android:layout_height="#dimen/friend_big"
android:layout_alignParentLeft="true"
android:scaleType="centerCrop"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="8dp"
android:layout_toRightOf="#+id/friend_img"
>
<TextView
android:id="#+id/friend_name[**"**]
android:layout_toRightOf="#id/friend_img"
android:layout_marginBottom="#dimen/layout_small_padding"
android:includeFontPadding="false"
android:paddingBottom="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:ellipsize="end"
android:gravity="top"
/>
<ViewStub
android:id="#+id/friend_sign"
android:inflatedId="#+id/friend_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="#layout/friend_sign_layout"/>
<TextView
android:id="#+id/friend_contact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:padding="5dp"
/>
</LinearLayout>
<ViewStub
android:id="#+id/friend_last_msg"
android:inflatedId="#+id/friend_last_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout="#layout/friend_last_msg"/>
You can to use this way:
Add an id -> #+id/container to parent
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_toRightOf="#+id/friend_img"
android:orientation="vertical">
For your stub layout just change to this:
<ViewStub
android:id="#+id/friend_last_msg"
android:inflatedId="#+id/friend_last_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/container"
android:layout_toRightOf="#+id/friend_img"
android:layout_alignParentRight="true"
android:layout="#layout/friend_last_msg"/>
I'm trying to achieve this positioning:
Where I have two rows of EditText and TextView next to each other.
The version textview is anchored to the bottom of the screen, but takes up the entire width and the text is centered.
My current layout file is this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:orientation="vertical"
android:gravity="center_vertical"
tools:context="com.example.mp.MainActivity$PlaceholderFragment" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edittext1"
android:layout_width="250dip"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NEW"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edittext2"
android:layout_width="250dip"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NEW"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dip"
android:gravity="bottom">
<TextView
android:id="#+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Version 1.0"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</RelativeLayout>
</LinearLayout>
But the two rows of EditText and TextView are positioned past the middle of the screen and the Version textview is immediately below the two rows of EditText and TextView instead of anchored at the bottom.
I would recommend using a RelativeLayout for the root layout and use the property android:layout_alignParentBottom="true" for the "version". Then wrap the other Views in a LinearLayout. Something like
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
<EditText
android:id="#+id/edittext1"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textview1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="NEW"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/edittext2"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textview2"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:text="NEW"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Version 1.0"
android:textColor="#444444"
android:paddingLeft="5dip"
android:textSize="10pt"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
I haven't had a chance to really test it but this should get you pretty close. I wrapped the two sets of Views in the center in a LinearLayout then gave each their own LinearLayout so they can make use of weight (which you can adjust to your needs). The parent LinearLayout is centered vertical so that those 4 Views will be centered the way I believe you want.
<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">//hope this will work for you
<LinearLayout
android:id="#+id/alltextfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"`enter code here`
android:orientation="horizontal" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="EditText" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New" />
</LinearLayout>
<LinearLayout
android:id="#+id/alltextfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="EditText" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New" />
</LinearLayout>
How do i align the arrows to be right above/below the numbers? Does each arrow need to have it's own linear layout? Is there a way to set this without setting a static amount of padding? I would like this to be generic enough to be used and show up properly on different devices...
I'm relatively new to android development - especially the UI portion of it... so any help would be appreciated!
What I See (Above)
What I Would Like To See (Above)
You can nest another LinearLayout (with orientation:vertical) inside your LinearLayout (with orientation:horizontal).
<?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="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageButton
android:id="#+id/number_picker_up_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/up"
android:background="#drawable/up" />
<TextView
android:id="#+id/one"
android:text="100"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/OffWhite"
android:textSize="40sp"
/>
<ImageButton
android:id="#+id/number_picker_down_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/down"
android:background="#drawable/down" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageButton
android:id="#+id/number_picker_up_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/up"
android:background="#drawable/up" />
<TextView
android:id="#+id/two"
android:text="100"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/OffWhite"
android:textSize="40sp"
/>
<ImageButton
android:id="#+id/number_picker_down_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/down"
android:background="#drawable/down" />
</LinearLayout>
</LinearLayout>
Note that nesting too many layouts inside a layout is discouraged. Reference:
http://developer.android.com/training/improving-layouts/optimizing-layout.html
But having 2 layout hierarchy is totally fine.
You need to nest two vertical LinearLayouts inside of your horizontal LinearLayout. Here's one where I do the same thing but I have empty Views on each side and one in the middle. You can take those out if you don't want them and obviously change your ids, backgrounds, and such
<LinearLayout
android:id="#+id/mpImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="10dp">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".5"/>
<LinearLayout
android:id="#+id/mpLL"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:layout_gravity="left"
android:orientation="vertical">
<ImageButton
android:id="#+id/mpUpBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
style="#style/UpArrow"
android:onClick="cycleUp"/>
<TextView
android:id="#+id/mpTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="breakfast"
android:gravity="center"
android:layout_gravity="center"
android:textSize="40sp"
android:textColor="#drawable/black"/>
<ImageButton
android:id="#+id/mpDownBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="cycleDown"
style="#style/DownArrow"/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".5"/>
<LinearLayout
android:id="#+id/catLL"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:layout_gravity="left"
android:orientation="vertical">
<ImageButton
android:id="#+id/catUpBtn"
style="#style/UpArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="cycleUp" />
<TextView
android:id="#+id/catTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beef"
android:gravity="center"
android:layout_gravity="center"
android:textSize="40sp"
android:textColor="#drawable/black" />
<ImageButton
android:id="#+id/catDownBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="cycleDown"
style="#style/DownArrow" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".5"/>
</LinearLayout>
You will notice I have also used weight and a 0dp for the width of the nested LinearLayouts and for the View to give them the separation I wanted and to look right on different screen sizes. You can change those depending on your needs.
You can have nested layouts. Be careful not to have too many, however two should be fine. Here is an example of what I think you are looking for. The arrows and text should be aligned thanks to RelativeLayout.
<?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="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageButton
android:id="#+id/number_picker_up_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/up"
android:src="#drawable/up" />
<TextView
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/number_picker_up_one"
android:text="100"
android:textColor="#color/OffWhite"
android:textSize="40sp" />
<ImageButton
android:id="#+id/number_picker_down_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/one"
android:layout_centerHorizontal="true"
android:background="#drawable/down"
android:src="#drawable/down" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageButton
android:id="#+id/number_picker_up_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/up"
android:src="#drawable/up" />
<TextView
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/number_picker_up_two"
android:text="100"
android:textColor="#color/OffWhite"
android:textSize="40sp" />
<ImageButton
android:id="#+id/number_picker_down_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/two"
android:layout_centerHorizontal="true"
android:background="#drawable/down"
android:src="#drawable/down" />
</RelativeLayout>
</LinearLayout>