Good day guys. I seriously need someone help to adjust my xml layout.
The above image shows the ListView, where it supposes to look like :
Image on the left, text on the right
Claims Type : Project
Amount : 100
Description : Trainning
xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="start"
android:background="#android:color/white"
android:padding="12dp">
<ImageView
android:id="#+id/image"
android:layout_width="80dp"
android:layout_height="70dp"
android:layout_centerVertical="true"
android:layout_gravity="left"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/image"
android:layout_marginRight="4dp"
android:layout_centerVertical="true"
android:paddingLeft="6dp"
android:orientation="vertical">
<TextView
android:id="#+id/Claimtype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Claims Type : "
android:maxLines="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/type"
android:layout_toRightOf="#+id/Claimtype"/>
<TextView
android:id="#+id/Amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#android:color/secondary_text_dark_nodisable"
android:text="Amount : "
android:maxLines="1"
android:ellipsize="end"
android:layout_below="#+id/Claimtype" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/amount"
android:layout_toRightOf="#+id/Amount"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#android:color/secondary_text_dark_nodisable"
android:text="Description : "
android:maxLines="1"
android:layout_below="#+id/Amount" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/description"
android:layout_toRightOf="#+id/Description"/>
</RelativeLayout>
</RelativeLayout>
Thanks a lot ..
Simply you just need a LinearLayout:
<?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="horizontal"
android:weightSum="1">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:id="#+id/imageView"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:id="#+id/textView"/>
</LinearLayout>
And create String like:
Claims Type : "yourType" + "\n"
Amount : 100 + "\n"
Description : Trainning + "\n"
to set for your TextView
You can try that, i do it, fast so it's not really beautiful but it's what you want (i think). Try to not put solid value.
<?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="wrap_content"
android:orientation="horizontal"
android:gravity="start"
android:background="#android:color/white"
android:padding="12dp">
<ImageView
android:id="#+id/image"
android:layout_width="80dp"
android:layout_height="70dp"
android:layout_centerVertical="true"
android:layout_gravity="left"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/image"
android:layout_centerVertical="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/Claimtype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Claims Type : "
android:maxLines="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/type"
android:layout_toRightOf="#+id/Claimtype"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/image"
android:layout_centerVertical="true"
android:orientation="horizontal">
<TextView
android:id="#+id/Amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#android:color/secondary_text_dark_nodisable"
android:text="Amount : "
android:maxLines="1"
android:ellipsize="end"
android:layout_below="#+id/Claimtype" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/amount"
android:layout_toRightOf="#+id/Amount"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/image"
android:layout_centerVertical="true"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#android:color/secondary_text_dark_nodisable"
android:text="Description : "
android:maxLines="1"
android:layout_below="#+id/Amount" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/description"
android:layout_toRightOf="#+id/Description"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
For performance purposes, do not embed RelativeLayouts one into another. Since you only have two child in the parent RelativeLayout, you can use a LinearLayout instead.
Now regarding your issue :
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/amount"
android:layout_toRightOf="#+id/Amount"/>
layout_toRightOf means the TextView will be place at the right of the indicated View, only horizontally. You need to add a layout_below attribute also.
try this, I have done it into my workspace.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mytextview="http://schemas.android.com/apk/res/com.bne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rlMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp" >
<ImageView
android:id="#+id/imgCover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/ic_launcher" />
<RelativeLayout
android:id="#+id/rlHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="2dp"
android:layout_toLeftOf="#+id/imgArrow"
android:layout_toRightOf="#+id/imgCover" >
<TextView
android:id="#+id/txtCoverHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:textSize="14sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlCT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/imgCover" >
<TextView
android:id="#+id/txtCT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/txtDateTime"
android:gravity="center"
android:text="Claims Type :"
android:textColor="#android:color/black"
android:textSize="10sp" />
<TextView
android:id="#+id/txtOutCT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/txtCT"
android:gravity="center"
android:text="Project"
android:textColor="#android:color/black"
android:textSize="10sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rlCT"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/imgCover" >
<TextView
android:id="#+id/txtAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/txtDateTime"
android:gravity="center"
android:text="Amount :"
android:textColor="#android:color/black"
android:textSize="10sp" />
<TextView
android:id="#+id/txtOutAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/txtAmount"
android:gravity="center"
android:text="100"
android:textColor="#android:color/black"
android:textSize="10sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlTraining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rlAmount"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/imgCover" >
<TextView
android:id="#+id/txtTraining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/txtDateTime"
android:gravity="center"
android:text="Description :"
android:textColor="#android:color/black"
android:textSize="10sp" />
<TextView
android:id="#+id/txtOutTraining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/txtTraining"
android:gravity="center"
android:text="Trainning"
android:textColor="#android:color/black"
android:textSize="10sp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Use this and let me know if some issue
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="start"
android:background="#android:color/white"
android:padding="12dp">
<ImageView
android:id="#+id/image"
android:layout_width="80dp"
android:layout_height="70dp"
android:layout_centerVertical="true"
android:layout_gravity="left"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/image"
android:layout_centerVertical="true"
android:paddingLeft="6dp"
android:orientation="vertical"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<LinearLayout
android:id="#+id/ll1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/Claimtype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Claims Type : "
android:singleLine="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/type"
android:text="dsjfhjh"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/ll2"
android:layout_below="#+id/ll1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/Amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#android:color/secondary_text_dark_nodisable"
android:text="Amount : "
android:maxLines="1"
android:ellipsize="end" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/amount"
android:text="dsjfhjsdkh" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll3"
android:layout_below="#+id/ll2"
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:textSize="14sp"
android:textColor="#android:color/secondary_text_dark_nodisable"
android:text="Description : "
android:maxLines="1"
android:layout_below="#+id/Amount" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/description"
android:text="jksdhfj"
android:layout_toRightOf="#+id/Description"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Related
Please Refer to screen shot.
Now my Problem is
i have make a xml design that is like in screenshot.
i have 4 relative layout contains imageview and textview.
now i want to set these 4 relative layout horizontally with equal space from right,left,start,end.
In my layout when it go on big screen the start and end showing extra space,i know i have set it like that.
But Is there any solution to set these RLs automatic adjust there size according to screen size.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/one"
android:id="#+id/RL_MainCat"
android:background="#color/white"
android:layout_marginTop="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/RL_UploadPres"
android:layout_marginLeft="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/upload_pres_icon"
android:id="#+id/icon_uploadpres"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Upload\nPrescription"
android:textAlignment="center"
android:textColor="#1f222d"
android:textSize="11sp"
android:layout_below="#+id/icon_uploadpres"
android:layout_marginTop="10dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/RL_UploadPres"
android:id="#+id/RL_FindPharmacy"
android:layout_marginLeft="20dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/find_pharma_icon"
android:id="#+id/icon_findphar"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Find \n Pharmacy "
android:textAlignment="center"
android:textColor="#1f222d"
android:textSize="11sp"
android:layout_below="#+id/icon_findphar"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/RL_FindPharmacy"
android:id="#+id/RL_BuyOTC"
android:layout_marginLeft="20dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/otc_icon"
android:id="#+id/icon_findotc"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Buy \n OTC "
android:textAlignment="center"
android:textColor="#1f222d"
android:textSize="11sp"
android:layout_below="#+id/icon_findotc"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/RL_BuyMedicine"
android:layout_toRightOf="#+id/RL_BuyOTC"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/medicine_icon"
android:id="#+id/icon_findmedi"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Buy \n Medicines "
android:textColor="#1f222d"
android:textSize="11sp"
android:textAlignment="center"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_below="#+id/icon_findmedi"
/>
</RelativeLayout>
</RelativeLayout>
Try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RL_MainCat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/one"
android:layout_marginTop="10dp"
android:background="#ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/RL_UploadPres"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp">
<ImageView
android:id="#+id/icon_uploadpres"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/icon_uploadpres"
android:layout_marginTop="10dp"
android:text="Upload\nPrescription"
android:textAlignment="center"
android:textColor="#1f222d"
android:textSize="11sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RL_FindPharmacy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:layout_toRightOf="#+id/RL_UploadPres">
<ImageView
android:id="#+id/icon_findphar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/icon_findphar"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text=" Find \n Pharmacy "
android:textAlignment="center"
android:textColor="#1f222d"
android:textSize="11sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RL_BuyOTC"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/RL_FindPharmacy">
<ImageView
android:id="#+id/icon_findotc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#mipmap/ic_launcher"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/icon_findotc"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text=" Buy \n OTC "
android:textAlignment="center"
android:textColor="#1f222d"
android:textSize="11sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RL_BuyMedicine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:layout_toRightOf="#+id/RL_BuyOTC">
<ImageView
android:id="#+id/icon_findmedi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/icon_findmedi"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text=" Buy \n Medicines "
android:textAlignment="center"
android:textColor="#1f222d"
android:textSize="11sp" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
Below Output
Use the relative layouts inside a Linear Layout having horizontal Orientation with Weightsum 4 or 1. and give each relative layout a weight of 1 or .25
Inside Relative layout width is set to 0dp so that the Layout will divide the Width equally when the weight is added
Use Scalable SP (ssp) and Scalable DP (sdp) instead of sp and dp so that the Dimenssions will be adjusted automatically too
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".25">
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".25">
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".25">
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".25">
</RelativeLayout>
</LinearLayout>
Try this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/one"
android:id="#+id/RL_MainCat"
android:background="#color/white"
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true">
<RelativeLayout
android:layout_weight="0.25"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/RL_UploadPres"
android:layout_marginLeft="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/upload_pres_icon"
android:id="#+id/icon_uploadpres"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Upload\nPrescription"
android:textAlignment="center"
android:textColor="#1f222d"
android:textSize="11sp"
android:layout_below="#+id/icon_uploadpres"
android:layout_marginTop="10dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_weight="0.25"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/RL_UploadPres"
android:id="#+id/RL_FindPharmacy"
android:layout_marginLeft="20dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/find_pharma_icon"
android:id="#+id/icon_findphar"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Find \n Pharmacy "
android:textAlignment="center"
android:textColor="#1f222d"
android:textSize="11sp"
android:layout_below="#+id/icon_findphar"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:layout_weight="0.25"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/RL_FindPharmacy"
android:id="#+id/RL_BuyOTC"
android:layout_marginLeft="20dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/otc_icon"
android:id="#+id/icon_findotc"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Buy \n OTC "
android:textAlignment="center"
android:textColor="#1f222d"
android:textSize="11sp"
android:layout_below="#+id/icon_findotc"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_weight="0.25"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/RL_BuyMedicine"
android:layout_toRightOf="#+id/RL_BuyOTC"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/medicine_icon"
android:id="#+id/icon_findmedi"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Buy \n Medicines "
android:textColor="#1f222d"
android:textSize="11sp"
android:textAlignment="center"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_below="#+id/icon_findmedi"
/>
</LinearLayout>
</RelativeLayout>
I am facing android design issue , I can't understand why it happened it is weird.
My layout code :
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<RelativeLayout
android:id="#+id/outgoing_layout_bubble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_marginRight="8dp"
android:background="#drawable/chatrectbg"
android:padding="10dp"
android:visibility="visible">
<TextView
android:id="#+id/message"
style="#style/chat_text_message_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="#+id/time"
android:autoLink="web"
android:paddingRight="10dp"
android:text="#{chat.messageText}"
android:textColor="#android:color/white"
android:textStyle="bold" />
<TextView
android:id="#id/time"
style="#style/chat_timings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="4dp"
android:padding="5dp"
android:paddingRight="10dp"
android:text="#{chat.messageTime}"
android:textColor="#android:color/white"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
preview of this code is as below :
I want background color change wrapping text, but it doesn't.
I can't understand what I am doing wrong?
You can try like 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="wrap_content"
android:padding="10dp"
android:layout_gravity="end"
android:gravity="end"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#555"
android:padding="10dp"
android:gravity="end|center_vertical"
android:layout_gravity="right"
android:orientation="vertical">
<TextView
android:id="#+id/message"
style="#style/chat_text_message_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="Message "
android:textColor="#android:color/white"
android:textStyle="bold" />
<TextView
android:id="#id/time"
style="#style/chat_timings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/message"
android:padding="5dp"
android:gravity="right"
android:text="Time"
android:textColor="#android:color/white"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
I am trying to add three text views as follows, but I could not able to achieve it. I want A to be on the left side, and the other two texviews to be right side.
Here is what I get:
Here is my current implementation
<RelativeLayout
android:id="#+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:background="#363636">
<TextView
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="A"
android:textColor="#android:color/white"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:textSize="16sp"
android:fontFamily="sans-serif-medium" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:id="#+id/innerLayout">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:text="B "
android:textSize="16sp"
android:textColor="#android:color/white"
android:paddingRight="8dp" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:text="C "
android:textSize="16sp"
android:textColor="#android:color/white"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:paddingLeft="8dp"
android:paddingRight="8dp" />
</RelativeLayout>
</RelativeLayout>
use this:
<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"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:id="#+id/A"
android:text="aaaaaaa"
android:padding="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:id="#+id/C"
android:text="ccccccc"
android:padding="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/C"
android:id="#+id/B"
android:text="bbbbbbb"
android:padding="8dp"/>
</RelativeLayout>
Change the xml like this ,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#363636"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<TextView android:background="#458765"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:fontFamily="sans-serif-medium"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:text="A"
android:textColor="#android:color/white"
android:textSize="16sp" />
<RelativeLayout
android:id="#+id/innerLayout"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentRight="true">
<TextView android:background="#458765"
android:id="#+id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="B"
android:textColor="#android:color/white"
android:textSize="16sp" />
<TextView android:layout_marginLeft="5dp" android:background="#458765"
android:layout_toRightOf="#id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="C"
android:textColor="#android:color/white"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
I am trying to create the following layout in android.
I am unable to achieve the layout as shown in the image.Please ignore the image on the extreme left.
<LinearLayout
android:id="#+id/ll_groups_list_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight="1.0"
android:background="#drawable/normal_white_bg"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/groups_list_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Group name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/groups_list_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:text="Group Description may come for two lines" />
</LinearLayout>
<ImageView
android:id="#+id/groups_list_image"
android:layout_width="70dp"
android:layout_height="70dp"
android:padding="3dip"
android:src="#drawable/logo" />
this may helpful to you,
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="2dp" >
<ImageView
android:id="#+id/image"
android:layout_width="120dp"
android:layout_height="120dp"
android:contentDescription="#string/news" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/arrow"
android:layout_toRightOf="#+id/thumb"
android:orientation="vertical" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="#string/text1"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginTop="25dp"
android:padding="2dp"
android:paddingTop="20dp"
android:text="#string/text2"
android:textColor="#7F7F7F"
android:textSize="10sp" />
</RelativeLayout>
<ImageView
android:id="#+id/textImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:src="#drawable/image_source" />
</RelativeLayout>
Try this way,hope this will help you to solve your problem.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFF00"
android:padding="5dp">
<LinearLayout
android:id="#+id/ll_groups_list_text"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:gravity="center_vertical"
android:padding="5dp">
<TextView
android:id="#+id/groups_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Group name"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/groups_list_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:text="Group Description may come for two lines" />
</LinearLayout>
<ImageView
android:id="#+id/groups_list_image"
android:layout_width="70dp"
android:layout_height="70dp"
android:padding="3dip"
android:background="#FFFFFF"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Please use this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFF00"
android:padding="2dp" >
<RelativeLayout
android:id="#+id/ll_groups_list_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#FFFFFF"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageView1"
android:text="Text1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignParentLeft="true"
android:text="Text 2"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
</LinearLayout>
I am creating a box that will show some data in that.I want to set the positions of the textview so that if the text size increase it can be handled easliy.
I have created this layout but the issue is if the text size i am getting larger from the server then it is getting messed up with each other how could we handle this.
XML
<?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="vertical" >
<RelativeLayout
android:id="#+id/result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="2dp"
android:layout_marginTop="5dp"
android:background="#layout/rectangle_shape" >
<TextView
android:id="#+id/approvalId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:text="ApprovalId :"
android:textStyle="bold" />
<TextView
android:id="#+id/approvalId_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/approvalId"
android:text="Co07039645" />
<TextView
android:id="#+id/admin_remarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/approvalId"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:text="AdminRemarks :"
android:textStyle="bold" />
<TextView
android:id="#+id/admin_remarks_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/admin_remarks"
android:layout_below="#+id/approvalId_value"
android:text="Test Remarks Done by Pooja who is the admin of the employee" />
<TextView
android:id="#+id/current_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/admin_remarks"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:text="Current Status :"
android:textStyle="bold" />
<TextView
android:id="#+id/current_status_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/current_status"
android:layout_below="#+id/admin_remarks_value"
android:text="Approved" />
<TextView
android:id="#+id/update_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/current_status"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:text="Update Time :"
android:textStyle="bold" />
<TextView
android:id="#+id/update_time_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/update_time"
android:layout_below="#+id/current_status_value"
android:text="2014-03-07 13:42:18" />
<TextView
android:id="#+id/previous_costcenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/update_time"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:text="Previous Costcenter :"
android:textStyle="bold" />
<TextView
android:id="#+id/previous_costcenter_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/previous_costcenter"
android:layout_below="#+id/update_time_value"
android:text="All" />
<TextView
android:id="#+id/current_costcenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/previous_costcenter"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:text="Previous Costcenter :"
android:textStyle="bold" />
<TextView
android:id="#+id/current_costcenter_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/current_costcenter"
android:layout_below="#+id/previous_costcenter_value"
android:text="All" />
</RelativeLayout>
</RelativeLayout>
Remarks will have the maximum length of data rest will similar as i have posted in the XML
Here according to your question you can't use Weight for Relativelayout. If you want to use then you can use Linear Layout with horizontal or vertical orientation. So answer from your question,
<?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:id="#+id/result"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="2dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/approvalId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="ApprovalId :"
android:textStyle="bold" />
<TextView
android:id="#+id/approvalId_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:text="Co07039645" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/admin_remarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:maxLines="5"
android:text="Admin Remarks :"
android:textStyle="bold" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" >
<TextView
android:id="#+id/admin_remarks_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Test Remarks Done by Pooja who is the admin of the employee" />
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/current_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="Current Status :"
android:textStyle="bold" />
<TextView
android:id="#+id/current_status_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Approved" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/update_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="Update Time :"
android:textStyle="bold" />
<TextView
android:id="#+id/update_time_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:text="2014-03-07 13:42:18" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/previous_costcenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="Previous Costcenter :"
android:textStyle="bold" />
<TextView
android:id="#+id/previous_costcenter_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="All" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/current_costcenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="Previous Costcenter :"
android:textStyle="bold" />
<TextView
android:id="#+id/current_costcenter_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="All" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
you can not. weight is defined for LinearLayout only. Here the documentation.
You can't set weight in RelativeLayout. If you want to maintain your layout with weight then you should use `Linearlayout.