Hi, I have two text view and one image view inside a relative layout,
I want to align image view centre according to textview parallel, but
now imagview aligning down parallel to text view, pls help me.i want result
as 1st image,but now am getting like second image
<LinearLayout
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:layout_width="0dp"
android:orientation="vertical">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_width="match_parent">
<TextView
android:id="#+id/totPendingTxt"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_width="wrap_content"
android:text="TOTAL"
android:textAllCaps="true"
android:textColor="#color/Color"
android:textSize="#dimen/text_size_small" />
<ImageView
android:contentDescription="#string/icon"
android:id="#+id/imgPendingOrder"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/totPendingTxt"
android:layout_width="wrap_content"
android:src="#drawable/icon_arrow" />
<TextView
android:id="#+id/totalPendingOrders"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:text=""
android:textAllCaps="true"
android:textColor="#color/Color"
android:textSize="#dimen/text_size_small" />
</RelativeLayout>
</LinearLayout>
Replace your code with my following code,may b it will help you:)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/totPendingTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TOTAL"
android:textAllCaps="true"
android:textColor="#color/Color"
android:textSize="#dimen/text_size_small" />
<ImageView
android:id="#+id/imgPendingOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/icon_arrow" />
<TextView
android:id="#+id/totalPendingOrders"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text=""
android:textAllCaps="true" />
</RelativeLayout>
</LinearLayout>
Related
I want to place a textview to the right and gravity centre of the Image View. I am using Relative Layout for that. Using Relative Layout, i am able to set the Textview to the right side of the Image view.But not able to set it to the centre. I mean here center is not inside of the Imageview, i want to place Textview to the right centre of Imageview(outside centre of Imageview).I am not able to set to centre.
Anybody please help me out.I want to do this only in relative layout.
Here is my xml,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:layout_width="match_parent">
<TextView
android:id="#+id/name_text_view"
android:textSize="20sp"
android:layout_toRightOf="#id/image_view"
android:layout_width="wrap_content"
android:textColor="#color/black"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
<ImageView
android:id="#+id/image_view"
android:layout_marginLeft="30dp"
android:layout_width="50dp"
android:layout_height="50dp"/>
<Button
android:id="#+id/button"
android:layout_centerHorizontal="true"
android:background="#color/blue"
android:textColor="#color/color_white"
android:layout_marginTop="20dp"
android:layout_below="#id/name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/val_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:layout_marginTop="20dp"
android:textSize="18sp"
android:layout_centerHorizontal="true"
android:layout_below="#id/button"/>
</RelativeLayout>
You can do it with this code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp">
<ImageView
android:id="#+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="center"
android:src="#drawable/ic_launcher_background" />
<TextView
android:id="#+id/name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/image_view"
android:layout_centerInParent="true"
android:text="hello world"
android:textColor="#color/black"
android:textSize="12sp" />
</RelativeLayout>
Use this code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:layout_width="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
>
<ImageView
android:id="#+id/image_view"
android:layout_marginLeft="30dp"
android:layout_width="50dp"
android:layout_height="50dp"/>
<TextView
android:id="#+id/name_text_view"
android:textSize="20sp"
android:layout_toRightOf="#id/image_view"
android:layout_width="wrap_content"
android:textColor="#color/black"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
</LinearLayout>
<Button
android:id="#+id/button"
android:layout_centerHorizontal="true"
android:background="#color/blue"
android:textColor="#color/color_white"
android:layout_marginTop="20dp"
android:layout_below="#id/name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/val_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:layout_marginTop="20dp"
android:textSize="18sp"
android:layout_centerHorizontal="true"
android:layout_below="#id/button"/>
</RelativeLayout>
You can add this in your textview
android:layout_centerInParent="true"
Do You want this view? then try this code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:layout_width="match_parent">
<LinearLayout
android:id="#+id/leaner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="#+id/image_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="30dp"
android:contentDescription="TODO"
app:srcCompat="#mipmap/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/val_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Value"
android:textColor="#android:color/black"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/leaner1"
android:layout_marginTop="1dp"
android:background="#android:color/holo_blue_dark"
android:text="button"
android:textColor="#android:color/white" />
</RelativeLayout>
I have an issue trying align textView to the center of layout: when I try to do this - it has a conflict with a button on the left - if text is too long - it become hidden under the button. Text length can be very different and I need it in the center of layout but not under/on the button.
Here is the xml file of activity layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/item_content_action_bar_layout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/colorBlue"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:autoText="false"
android:layout_centerInParent="true"
android:layout_alignWithParentIfMissing="false"
android:layout_alignParentRight="false" />
<ImageButton
android:layout_width="120dp"
android:layout_height="45dp"
android:id="#+id/item_content_back_button"
android:background="#drawable/back_button_selector"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginRight="5dp" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/item_content_scroll_view"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="125dp"
android:layout_height="125dp"
android:id="#+id/item_content_image"
android:src="#drawable/ic_no_thumbnail"
android:maxHeight="125dp"
android:maxWidth="125dp"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:layout_margin="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_subtitle"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Subtitle"
android:layout_alignTop="#+id/item_content_image"
android:layout_toRightOf="#+id/item_content_image"
android:layout_toEndOf="#+id/item_content_image"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_pubdate"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Date"
android:layout_below="#+id/item_content_subtitle"
android:layout_alignLeft="#+id/item_content_subtitle"
android:layout_alignStart="#+id/item_content_subtitle"
android:textSize="10dp"
android:layout_marginTop="10dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="blabla"
android:layout_below="#+id/item_content_pubdate"
android:layout_alignStart="#+id/item_content_pubdate"
android:layout_alignParentStart="true"
android:layout_margin="10dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Try using LinearLayout with layout-weight for this to avoid conflict. Change your first relativelayout to below one
<LinearLayout
android:id="#+id/item_content_action_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="7">
<ImageButton
android:id="#+id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="2"
android:background="#drawable/chemist" />
<TextView
android:id="#+id/item_content_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="5"
android:autoText="false"
android:gravity="center"
android:maxLines="2"
android:singleLine="true"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/Black"
android:textStyle="bold" />
</LinearLayout>
Change Your RelativeLayout to LinearLayout and use android:layout_weight attribute of layout to do this.
<LinearLayout
android:id="#+id/item_content_action_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1"
>
<ImageButton
android:id="#+id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/chemist" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="1"
android:autoText="false"/>
</LinearLayout>
Make the layout_gravity of the textview item_content_title as "center_horizontal".
And add android:layout_toLeftOf="#+id/item_content_title" under the ImageButton item_content_back_button.
Hope it was what you wanted.
Your Action bar layout has to be like this-
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/item_content_action_bar_layout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/colorBlue"
android:padding="10dp">
<ImageButton
android:layout_width="120dp"
android:layout_height="45dp"
android:id="#+id/item_content_back_button"
android:background="#drawable/back_button_selector"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dp" />
<TextView
android:toRightOf="#id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:autoText="false"
android:layout_centerInParent="true" />
</RelativeLayout>
I'm trying to add an ImageButton at first, and here is the XML that contains it:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:id="#+id/name_search_layout"
android:background="#android:color/darker_gray"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/label_name"
android:text="#string/name_label"
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/text_name"
android:hint="#string/name_hint"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_expand"
android:layout_gravity="right"
android:src="#android:drawable/btn_plus"
/>
</LinearLayout>
This is inside another LinearLayout, but my button don't appear, it shows like this:
How can i make it appear?
Your imageButton not show, because, the width of EditText is match_parent, please change it to wrap_content like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:id="#+id/name_search_layout"
android:background="#android:color/darker_gray">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/label_name"
android:text="#string/name_label"
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textStyle="bold" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text_name"
android:hint="#string/name_hint"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button_expand"
android:layout_gravity="right"
android:src="#android:drawable/btn_plus"
/>
I am trying the following layout,in that I want to shift image to right but because linear layout is vertically oriented extra spaces are added between textview and image.
I dont want to use Relative layout because I am editing someone else's code and it is just the part of the code.
<LinearLayout
android:id="#+id/llSpouse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/tv_spouse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="SPOUSE"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
<com.ypomumbai.utills.CircularNetworkImageView
android:id="#+id/iv_picture"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="right"
android:layout_alignParentRight="true"
android:src="#android:drawable/ic_menu_info_details" />
<TextView
android:id="#+id/tvSpouseFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="First Name"
android:textStyle="bold" />
<TextView
android:id="#+id/tvSpouseLastName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_name"
android:layout_marginLeft="10dp"
android:text="Last Name" />
<TextView
android:id="#+id/tvSpousedesignation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_last_name"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="MD and CEO" />
<TextView
android:id="#+id/tvSpouseCompnayName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_designation"
android:layout_marginLeft="10dp"
android:text="Text" />
</View>
</LinearLayout>
Can anyone help on this.
How to shift image to right without getting extra spaces.
In Vertical linear layout every view will occupy the total row space. So add the margin bottom property to your com.ypomumbai.utills.CircularNetworkImageView with the height of that view.(negative margin will remove the space occupied by this view)
<com.ypomumbai.utills.CircularNetworkImageView
android:id="#+id/iv_picture"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginBottom="-80dp"
android:src="#android:drawable/ic_menu_info_details" />
I don't really understand if you don't want to use a RelativeLayout at all, but I post a sample of code that should work with a relative layout and without breaking the rest :
<LinearLayout
android:id="#+id/llSpouse"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/tv_spouse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="SPOUSE"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvSpouseFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="First Name"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvSpouseLastName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_name"
android:layout_marginLeft="10dp"
android:text="Last Name"/>
<TextView
android:id="#+id/tvSpousedesignation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_last_name"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="MD and CEO"/>
<TextView
android:id="#+id/tvSpouseCompnayName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_designation"
android:layout_marginLeft="10dp"
android:text="Text"/>
</LinearLayout>
<ImageView
android:id="#+id/iv_picture"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:src="#android:drawable/ic_menu_info_details"/>
</RelativeLayout>
</LinearLayout>
which renders the following :
EDIT
You can have the same render without RelativeLayout with the following xml :
<LinearLayout
android:id="#+id/llSpouse"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/tv_spouse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="SPOUSE"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvSpouseFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="First Name"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvSpouseLastName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Last Name"/>
<TextView
android:id="#+id/tvSpousedesignation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="MD and CEO"/>
<TextView
android:id="#+id/tvSpouseCompnayName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Text"/>
</LinearLayout>
<ImageView
android:id="#+id/iv_picture"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="right"
android:src="#android:drawable/ic_menu_info_details"/>
</LinearLayout>
</LinearLayout>
I am having an issue with getting my date TextView to be below my unit TextView when the activity name is too long in the rows for my ListView.
Here is my row layout code for my listview:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Name"
android:id="#+id/activityName"
android:textSize="25dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/pound"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="unit"
android:id="#+id/unit"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:id="#+id/slash"
android:layout_toLeftOf="#+id/unit"
android:layout_centerVertical="true"
android:layout_marginRight="2dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number"
android:id="#+id/number"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/slash"
android:layout_marginRight="5dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#"
android:id="#id/pound"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/number"
android:layout_marginRight="2dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:id="#+id/date"
android:layout_below="#+id/unit"
android:layout_alignRight="#+id/unit"
android:textSize="10sp" />
</RelativeLayout>
My ListView rows look like this:
Question:
How do I get my date TextView to always be below my unit TextView? Also for the pound, number, slash, and unit TextViews to be all on the same line and all above the date Textview. As well as the activityName TextView to be the left of the pound TextView so it does not overlap with the pound, number, slash, and unit TextViews. Like what the walk and exercise rows look like.
Take a LinearLayout for right sided items(unit,date,slash etc.)
put it in relative layout and set as align_parentright = "true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:paddingRight="10dip" >
<TextView
android:id="#+id/activityName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/verticalLayout"
android:text="New Name"
android:textSize="25sp" />
<LinearLayout
android:id="#id/verticalLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/pound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="2dp"
android:text="#"
android:textSize="20sp" />
<TextView
android:id="#+id/unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="unit"
android:textSize="20sp" />
<TextView
android:id="#+id/slash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="2dp"
android:text="/"
android:textSize="20sp" />
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number"
android:textSize="20sp" />
</LinearLayout>
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Date"
android:textSize="10sp" />
</LinearLayout>
</RelativeLayout>
Try putting the pound TextView & the date TextView inside a vertical LinearLayout, and then have the LinearLayout be aligned to center vertically and to the right.
Hope this helps :)
// try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:gravity="center">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="New Name"
android:id="#+id/activityName"
android:textSize="25dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#"
android:id="#+id/pound"
android:layout_marginRight="2dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number"
android:id="#+id/number"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:id="#+id/slash"
android:layout_marginRight="5dp"
android:textSize="20dp" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="unit"
android:id="#+id/unit"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:id="#+id/date"
android:layout_marginTop="3dp"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
If you have such problem in ListView make sure that you use proper inflation method. Parent view group must be specified for correct inflation.
mLayoutInflater.inflate(R.layout.listitem, parent, false);
Instead of
mLayoutInflater.inflate(R.layout.listitem, null);