How to set RelativeLayout parent right side - android

Hi I am very new for android and here I have created two RelativeLayout on LinearLayout
My requirement is I want to set second Relative Layout at parent right side
According to my code screen seems to be like my below image
So how can I set second RelativeLayout at parent right side
code:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/holo_blue_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ItemCode"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="GG00929-023"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="176000"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="0dp"
android:background="#android:color/holo_red_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="On Hand"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reserve"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.68"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cut Qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.00"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Balance"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>

Try this Layout. I have applied some changes to your Layout. I have remove child Linear Layout because it is useless or android:layout_alignParentRight="true" will not get affected. Also added Relative Layout as your Root Layout.
<?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="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/RL1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/holo_blue_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ItemCode"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="GG00929-023"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="176000"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#android:color/holo_red_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="On Hand"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reserve"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.68"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cut Qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.00"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Balance"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>

Linear Layout has no such attribute to set Right:
So you have to add the view with weight which will coverup the middle blank space.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/holo_blue_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ItemCode"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="GG00929-023"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="176000"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="0dp"
android:background="#android:color/holo_red_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="On Hand"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reserve"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.68"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cut Qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.00"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Balance"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

Between the two RelativeLayout, insert a third View:
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
Because of it's layout weight, this will "push" your second RelativeLayout to the right side.

In order to use android:layout_alignParentRight="true", the parent should be RelativeLayout. The parent of your RelativeLayout is LinearLayout and if I'm not mistaken, you want that RelativeLayout to be at the right of parent. Either make the parent RelativeLayout, or give weight_sum to LinearLayout and weight to the children.

Try it in second RelativeLayout
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="0dp"
android:background="#android:color/holo_red_light">
android:layout_alignParentRight attribute only work in children of RelativeLayout. Now, you are using it in a child of a LinearLayout so it will not work.

You have few ways to do what you require. Ill give you 2.
First you can change the "Parent Layout" to Relative and add alignParentRight="true" and alignParentLeft="true" for the two LinearLayout.
Second, with the way you did it, you can change to width of the two LinearLayout to 0dp and then, add them layout_weight="1".

Try this code ::
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
android:padding="5dp">
<RelativeLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#android:color/holo_blue_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ItemCode"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="GG00929-023"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="176000"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="0dp"
android:background="#android:color/holo_red_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="On Hand"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reserve"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.68"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cut Qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.00"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Balance"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>

Related

Listview can't displayed the last item

This is the my current listivew:
My problem is i can't display my last item in the list. It's like getting cut by my phone.
Here is the xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<RelativeLayout
android:orientation="vertical"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="280dp"
android:background="#drawable/dfcomment3"
android:layout_weight="0.07">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Add comment"
android:id="#+id/button12"
android:layout_marginTop="215dp"
android:layout_marginLeft="5dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Update Post"
android:id="#+id/button13"
android:layout_marginTop="215dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Close This"
android:id="#+id/button14"
android:layout_marginTop="215dp" />
</LinearLayout>
<TextView
android:layout_marginLeft="10dp"
android:textSize="35dp"
android:id="#+id/textView11"
android:gravity="center"
android:text="ID"
android:textStyle="bold"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView12"
android:text="Name"
android:textSize="16dp"
android:textColor="#994495"
android:layout_marginTop="190dp"
android:layout_marginLeft="210dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView13"
android:text="Lastname"
android:textStyle="bold"
android:textSize="16dp"
android:layout_marginLeft="90dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/id"
android:layout_toEndOf="#+id/id"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/textView14"
android:text="title"
android:textSize="15dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260dp"
android:layout_below="#+id/name"
android:layout_alignStart="#+id/name"
android:layout_marginTop="190dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="descr"
android:textSize="21dp"
android:textColor="#994495"
android:id="#+id/textView15"
android:layout_marginLeft="110dp"
android:layout_marginTop="60dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dept"
android:textStyle="italic"
android:textColor="#994495"
android:id="#+id/textView16"
android:layout_marginLeft="180dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tags"
android:textStyle="italic"
android:textSize="14dp"
android:textColor="#994495"
android:id="#+id/textView17"
android:layout_marginLeft="120dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"
android:textSize="25dp"
android:textStyle="bold"
android:textColor="#70CC86"
android:id="#+id/textView18"
android:layout_marginLeft="290dp"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"
android:textColor="#994495"
android:id="#+id/textView19"
android:layout_marginLeft="10dp"
android:layout_marginTop="190dp" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
As much as possible i want to stick with the listview because i'm not familiar with the recyclerview. if theres any way to fix this, i would be glad.
Check the image for the reference of my problem.
There's actually 4 items in the list and i can only view 2 items.
Firstly there is problem with your XML as when you use weightsum and layout_weight then you need not give dimensions in height or width.
This must be your XML.
Also I checked your XML there is some problem in you XML attributes too. Like you used "android:layout_below="#+id/id"" but in your xml there is no "id"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100">
<RelativeLayout
android:orientation="vertical"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#drawable/dfcomment3"
android:layout_weight="70">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Add comment"
android:id="#+id/button12"
android:layout_marginTop="215dp"
android:layout_marginLeft="5dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Update Post"
android:id="#+id/button13"
android:layout_marginTop="215dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Close This"
android:id="#+id/button14"
android:layout_marginTop="215dp" />
</LinearLayout>
<TextView
android:layout_marginLeft="10dp"
android:textSize="35dp"
android:id="#+id/textView11"
android:gravity="center"
android:text="ID"
android:textStyle="bold"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView12"
android:text="Name"
android:textSize="16dp"
android:textColor="#994495"
android:layout_marginTop="190dp"
android:layout_marginLeft="210dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView13"
android:text="Lastname"
android:textStyle="bold"
android:textSize="16dp"
android:layout_marginLeft="90dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/id"
android:layout_toEndOf="#+id/id"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/textView14"
android:text="title"
android:textSize="15dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260dp"
android:layout_below="#+id/name"
android:layout_alignStart="#+id/name"
android:layout_marginTop="190dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="descr"
android:textSize="21dp"
android:textColor="#994495"
android:id="#+id/textView15"
android:layout_marginLeft="110dp"
android:layout_marginTop="60dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dept"
android:textStyle="italic"
android:textColor="#994495"
android:id="#+id/textView16"
android:layout_marginLeft="180dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tags"
android:textStyle="italic"
android:textSize="14dp"
android:textColor="#994495"
android:id="#+id/textView17"
android:layout_marginLeft="120dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"
android:textSize="25dp"
android:textStyle="bold"
android:textColor="#70CC86"
android:id="#+id/textView18"
android:layout_marginLeft="290dp"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"
android:textColor="#994495"
android:id="#+id/textView19"
android:layout_marginLeft="10dp"
android:layout_marginTop="190dp" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_weight="30"
android:layout_height="0dp" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</LinearLayout>
Add your java code if you are not getting 4 values into your ListView
Change you xml to :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<RelativeLayout
android:orientation="vertical"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="280dp"
android:layout_weight="0.07"--> Delete this
>
....
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_weight="1" -> Add this
android:layout_height="0dp" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>

How to align textviews regarding to the layout background

I would like to know if there is a way to place all the textviews that start with little bit space regarding the layout they located. For example I want that in the follwoing image all the textvies will not touch in the border of layout sucah as the word "place","location","Between","When" are doing.
This is current situation:
and this is my xml code:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/relativlayoutGcmMessage"
android:background="#ffffff">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:id="#+id/separatorUp"
android:visibility="visible"
android:background="#FF0000"
android:layout_marginTop="25dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/textlayout"
android:layout_marginTop="5dp"
android:layout_below="#+id/separatorUp"
android:background="#drawable/edit_text_style_focused"
android:layout_margin="10dp"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User ,"
android:gravity="center"
android:id="#+id/textViewUser"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textSize="20sp"
android:textColor="#FF0000" />
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="this is the message"
android:textSize="20sp"
android:layout_marginLeft="5dp"
android:layout_below="#+id/textViewUser"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#000000" />
</RelativeLayout>
<LinearLayout
android:id="#+id/linearLayoutBtn"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:text="Join"
android:id="#+id/ButtonJoin"
android:textColor="#ffffff"
android:background="#606060"
android:layout_margin="10dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
>
</Button>
<Button
android:text="Deny"
android:id="#+id/ButtonDeny"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_margin="10dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="#ffffff"
android:background="#606060"
>
</Button>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/relativeLayoutTextVals"
android:layout_marginTop="20dp"
android:layout_margin="10dp"
android:background="#drawable/edit_text_style_focused"
android:layout_below="#+id/textlayout"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:id="#+id/row2"
android:layout_below="#+id/row1"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Between:"
android:id="#+id/textViewbtwn"
android:textColor="#FF0000"
android:textStyle="bold"
android:textSize="20sp"
android:layout_weight="0.62" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Time"
android:id="#+id/textViewtime"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:layout_weight="1.45"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/row3"
android:layout_below="#+id/row2"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Location:"
android:id="#+id/textViewloc"
android:textStyle="bold"
android:textColor="#FF0000"
android:textSize="20sp"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="place"
android:layout_marginLeft="10dp"
android:id="#+id/textViewPlace"
android:textSize="20sp"
android:layout_weight="2.28"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/row1"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="When:"
android:id="#+id/textViewWhen"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#FF0000"
android:layout_weight="51.15" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Date"
android:layout_marginLeft="10dp"
android:id="#+id/textViewDate"
android:textSize="20sp"
android:layout_weight="115.29"
android:textColor="#000000" />
</TableRow>
</RelativeLayout>
</RelativeLayout>
Try another approach as follows , it works as per your requirement
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativlayoutGcmMessage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<View
android:id="#+id/separatorUp"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="25dp"
android:background="#FF0000"
android:visibility="visible" />
<RelativeLayout
android:id="#+id/textlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/separatorUp"
android:layout_margin="10dp"
android:layout_marginTop="5dp"
android:padding="10dp">
<TextView
android:id="#+id/textViewUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="User ,"
android:textColor="#FF0000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textViewUser"
android:layout_marginLeft="5dp"
android:text="this is the message"
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>
<LinearLayout
android:id="#+id/linearLayoutBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="horizontal">
<Button
android:id="#+id/ButtonJoin"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#606060"
android:text="Join"
android:textColor="#ffffff"></Button>
<Button
android:id="#+id/ButtonDeny"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#606060"
android:text="Deny"
android:textColor="#ffffff">
</Button>
</LinearLayout>
<RelativeLayout
android:id="#+id/relativeLayoutTextVals"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textlayout"
android:layout_margin="10dp"
android:layout_marginTop="20dp">
<LinearLayout
android:id="#+id/row2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/row1"
android:layout_margin="5dp">
<TextView
android:id="#+id/textViewbtwn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Between:"
android:textColor="#FF0000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewtime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="Time"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/row3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/row2"
android:layout_margin="5dp">
<TextView
android:id="#+id/textViewloc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Location:"
android:textColor="#FF0000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewPlace"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="place"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/row1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center"
android:layout_margin="5dp"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="#+id/textViewWhen"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="When:"
android:textColor="#FF0000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewDate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="Date"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>

set linear layout outside the scrollview

I want last two textview in the bottom of the screen and outside the scrollview...but with my code i can get the linear layout inside the scrollview, If i will define them outside the scrollview..It gives me error:root element must be formated at the last linear layout structure
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView2"
android:background="#drawable/back1"
android:scrollbars="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:layout_marginTop="2dp"
android:text=""
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:text=""
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:text=""
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/textView5"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text=""
android:textColor="#FFFFFF" />
<TableLayout
android:id="#+id/maintable"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp" >
</TableLayout>
<TableLayout
android:id="#+id/maintable1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp" >
</TableLayout>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#android:id/list"
android:text=""
android:textColor="#FFFFFF" />
<ListView
android:id="#android:id/list"
style=" android:listViewStyle"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_below="#+id/textView6"
android:layout_marginLeft="33dp"
android:drawSelectorOnTop="true"
android:textColor="#FFFFFF" >
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="0dp"
android:orientation="horizontal"
>
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_gravity="bottom"
android:text=""
android:layout_marginBottom="5dp"
android:textColor="#FFFFFF"
android:textColorLink="#FFFFFF" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="1dp"
android:layout_marginBottom="5dp"
android:text=""
android:layout_gravity="bottom"
android:textColor="#FFFFFF"
android:textColorLink="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Try this, add/change the design yourself :)
<?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="match_parent"
android:background="#color/darkblue">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:scrollbars="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:layout_marginTop="2dp"
android:text="Hello"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:text="Hello"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:text="Hello"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/textView5"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text="Hello"
android:textColor="#FFFFFF" />
<TableLayout
android:id="#+id/maintable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp" >
</TableLayout>
<TableLayout
android:id="#+id/maintable1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp" >
</TableLayout>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#android:id/list"
android:text="Hello"
android:textColor="#FFFFFF" />
<ListView
android:id="#android:id/list"
style=" android:listViewStyle"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_below="#+id/textView6"
android:layout_marginLeft="33dp"
android:drawSelectorOnTop="true"
android:textColor="#FFFFFF" >
</ListView>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/scrollView"
android:orientation="horizontal">
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_gravity="bottom"
android:text="Hello"
android:layout_marginBottom="5dp"
android:textColor="#FFFFFF"
android:textColorLink="#FFFFFF" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="1dp"
android:layout_marginBottom="5dp"
android:text="Hello"
android:layout_gravity="bottom"
android:textColor="#FFFFFF"
android:textColorLink="#FFFFFF" />
</LinearLayout>
</RelativeLayout>

How to align a texview to the center

Android - How can I align the text to the center , the left texviews ¨t¨and ¨c¨should be align with the center of the imageview and the right textview ¨localTime" , why are they on top ?
Thanks Stackoverflow
Heres a pic of my layout , can see the difference ?
<LinearLayout
android:id="#+id/LinearLayout_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:weightSum="3.0" >
<TextView
android:id="#+id/localTimestamp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:gravity="left|center_vertical"
android:text="localTime"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="right|bottom"
android:weightSum="1.0" >
<TextView
android:id="#+id/weather"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:gravity="right|bottom"
android:text="w"
android:textColor="#FFFFFF"/>
<ImageView
android:id="#+id/ic_weather"
android:layout_width="25dip"
android:layout_height="25dip"
android:layout_toRightOf="#+id/weather"
android:background="#drawable/w_1"
android:contentDescription="#string/todo"
android:gravity="right|bottom" />
<TextView
android:id="#+id/temperature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/ic_weather"
android:gravity="right|bottom"
android:text="#string/t"
/>
<TextView
android:id="#+id/unitTemp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right|bottom"
android:layout_toRightOf="#+id/temperature"
android:text="#string/c"
/>
</RelativeLayout>
</LinearLayout>
add
android:layout_centerVertical="true"
for both of textviews
<TextView
android:id="#+id/temperature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/ic_weather"
android:gravity="right|bottom"
android:layout_centerVertical="true"
android:text="t" />
<TextView
android:id="#+id/unitTemp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/temperature"
android:gravity="right|bottom"
android:layout_centerVertical="true"
android:text="c" />
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp">
<TextView
android:id="#+id/localTimestamp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="localTime"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:layout_marginLeft="5dp">
<TextView
android:id="#+id/weather"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:visibility="invisible"
android:gravity="right|bottom"
android:text="w"
android:textColor="#FFFFFF"/>
<ImageView
android:id="#+id/ic_weather"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="#drawable/w_1"
android:layout_marginLeft="5dp"
android:contentDescription="#string/todo"/>
<TextView
android:id="#+id/temperature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/t"/>
<TextView
android:id="#+id/unitTemp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/c"/>
</LinearLayout>
</LinearLayout>
I think #Haresh is right. I am using almost same. Just remove string.
My xml code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<LinearLayout
android:id="#+id/LinearLayout_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:weightSum="3.0" >
<TextView
android:id="#+id/localTimestamp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:gravity="left|center_vertical"
android:text="localTime" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="right|bottom"
android:weightSum="1.0" >
<TextView
android:id="#+id/weather"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right|bottom"
android:text="w"
android:textColor="#FFFFFF"
android:visibility="invisible" />
<ImageView
android:id="#+id/ic_weather"
android:layout_width="25dip"
android:layout_height="25dip"
android:layout_toRightOf="#+id/weather"
android:gravity="right|bottom" />
<TextView
android:id="#+id/temperature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/ic_weather"
android:gravity="right|bottom" />
<TextView
android:id="#+id/unitTemp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/temperature"
android:gravity="right|bottom" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>

designing Custom tabs using linearlayout with child elements(Imageview,Textview)

I am creating custom tabs which consists of seven tabs using linear layout with imageview and Textview(Child elements) and giving weight equaly to seven tabs. But i need to set first tab width to remaining tabs so that it looks good.How to accompolish this. I am attaching screen shot for your kind reference.
XML File
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000000">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:requiresFadingEdge="horizontal"
android:fadingEdgeLength="2dp"
android:scrollbarStyle="outsideInset"
android:scrollbarSize="1dp"
android:scrollbarThumbHorizontal="#android:color/darker_gray"
android:overScrollMode="never"
android:fadeScrollbars="false"
android:background="#0668b1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:weightSum="7"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/ll_tab_wodetail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#464646"
android:padding="5dp"
android:orientation="vertical">
<ImageView
android:id="#+id/iv_icon_wodetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="false"
android:src="#drawable/wo_wodetails" />
<TextView
android:id="#+id/tv_icon_wodetail"
style="?android:attr/tabWidgetStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="W/O Details"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ll_tab_details"
android:background="#464646"
android:layout_weight="1"
android:layout_marginLeft="2dp"
android:padding="5dp"
android:orientation="vertical">
<ImageView
android:id="#+id/iv_icon_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:src="#drawable/wo_details"
android:adjustViewBounds="false" />
<TextView
android:id="#+id/tv_icon_wodetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Details"
android:textSize="16sp"
android:textColor="#ffffff"
style="?android:attr/tabWidgetStyle"
android:gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ll_tab_spares"
android:layout_weight="1"
android:background="#464646"
android:layout_marginLeft="2dp"
android:padding="5dp"
android:orientation="vertical">
<ImageView
android:id="#+id/iv_icon_spares"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wo_spares"
android:gravity="center_horizontal"
android:layout_weight="1"
android:adjustViewBounds="false" />
<TextView
android:id="#+id/tv_icon_spares"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Spares"
android:textSize="16sp"
android:textColor="#ffffff"
style="?android:attr/tabWidgetStyle"
android:gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ll_tab_tools"
android:background="#464646"
android:layout_weight="1"
android:layout_marginLeft="2dp"
android:padding="5dp"
android:orientation="vertical">
<ImageView
android:id="#+id/iv_icon_tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wo_tools"
android:gravity="center_horizontal"
android:layout_weight="1"
android:adjustViewBounds="false" />
<TextView
android:id="#+id/tv_icon_tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tools"
android:textSize="16sp"
android:textColor="#ffffff"
style="?android:attr/tabWidgetStyle"
android:gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ll_tab_tasks"
android:background="#464646"
android:layout_weight="1"
android:layout_marginLeft="2dp"
android:padding="5dp"
android:orientation="vertical">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wo_tasks"
android:gravity="center_horizontal"
android:adjustViewBounds="false" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tasks"
android:textSize="16sp"
android:textColor="#ffffff"
style="?android:attr/tabWidgetStyle"
android:gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ll_tab_costs"
android:background="#464646"
android:layout_weight="1"
android:layout_marginLeft="2dp"
android:padding="5dp"
android:orientation="vertical">
<ImageView
android:id="#+id/iv_icon_costs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wo_costs"
android:gravity="center_horizontal"
android:adjustViewBounds="false" />
<TextView
android:id="#+id/tv_icon_costs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Costs"
android:textSize="16sp"
android:textColor="#ffffff"
style="?android:attr/tabWidgetStyle"
android:gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ll_tab_trades"
android:background="#464646"
android:layout_weight="1"
android:layout_marginLeft="2dp"
android:padding="5dp"
android:orientation="vertical">
<ImageView
android:id="#+id/iv_icon_trades"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:src="#drawable/wo_trades"
android:adjustViewBounds="false" />
<TextView
android:id="#+id/tv_icon_trades"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Trades"
android:textSize="16sp"
android:textColor="#ffffff"
style="?android:attr/tabWidgetStyle"
android:gravity="center_horizontal" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<ScrollView
android:id="#+id/sv_wodetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:background="#000000">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#000000">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tv_wono"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Work Oder No"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tv_wonoval"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:background="#drawable/spinner_background"
android:textColor="#ffffff"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tv_equipment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Equipment"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tv_equipmentval"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:background="#drawable/spinner_background"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tv_equipmenthier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Equipment Hierarchy"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tv_equipmenthierval"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:background="#drawable/spinner_background"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tv_jobdesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Job Description"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/et_jobdesc"
android:textColor="#ffffff"
android:background="#drawable/spinner_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textSize="18sp">
<requestFocus />
</EditText>
<TextView
android:id="#+id/tv_instruction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Instruction"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:textColor="#ffffff"
android:id="#+id/et_instruction"
android:background="#drawable/spinner_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:layout_marginTop="5dp"
android:textSize="18sp">
<requestFocus />
</EditText>
<TextView
android:id="#+id/tv_safetynotes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Safety Notes"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/et_safetynotes"
android:background="#drawable/spinner_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:layout_marginTop="5dp"
android:textSize="18sp">
<requestFocus />
</EditText>
<TextView
android:id="#+id/tv_wotype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="W/O Type"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tv_wotypeval"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="WO TYPE"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:background="#drawable/spinner_background"
android:textColor="#ffffff"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dip"
android:orientation="vertical" />
</LinearLayout>
</RelativeLayout>

Categories

Resources