How to align these TextViews in my android application -


i have following layout:

enter image description here

as can see from date , to date not aligned because of number of characters in , label?

how align them?

here xaml layout:

<?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">       <linearlayout         android:layout_height="wrap_content"         android:layout_width="match_parent"         android:orientation="horizontal"         android:layout_margintop="5dip"         android:animatelayoutchanges="false">         <textview             android:layout_width="wrap_content"             android:layout_height="match_parent"             android:text="from"             android:paddingtop="10dp"             android:paddingleft="10dp"             android:gravity="center_vertical|center_horizontal"             />         <textview             android:id="@+id/start_date"             android:layout_width="0px"             android:layout_height="wrap_content"             android:layout_weight="7"             android:singleline="true"             android:paddingright="4dp"             android:paddingtop="15dp"             android:text="10-11-2016"             android:layout_marginright="0dp"             android:contentdescription="start date"             style="@style/textappearance.editevent_spinnerbutton" />         <textview             android:id="@+id/start_time"             android:layout_width="0px"             android:layout_height="wrap_content"             android:layout_weight="4"             android:paddingtop="15dp"             android:contentdescription="start time"             android:text="13:58"             android:layout_marginleft="0dip"             style="@style/textappearance.editevent_spinnerbutton" />     </linearlayout>        <linearlayout         android:layout_height="wrap_content"         android:layout_width="match_parent"         android:orientation="horizontal"         android:layout_margintop="5dip"         android:animatelayoutchanges="false">           <textview             android:id="@+id/to_label"             android:layout_height="wrap_content"             android:layout_width="wrap_content"             android:text="to"             android:paddingtop="10dp"             android:paddingleft="10dp"             android:gravity="center_vertical|center_horizontal"         />          <textview             android:id="@+id/end_date"             android:layout_width="0px"             android:layout_height="wrap_content"             android:layout_weight="7"             android:singleline="true"             android:paddingright="4dp"             android:paddingtop="15dp"             android:text="11-11-2016"             android:layout_marginright="0dp"             android:contentdescription="end date"             style="@style/textappearance.editevent_spinnerbutton" />         <textview             android:id="@+id/end_time"             android:layout_width="0px"             android:layout_height="wrap_content"             android:layout_weight="4"             android:paddingtop="15dp"             android:contentdescription="end time"             android:text="23:59"             android:layout_marginleft="0dip"             style="@style/textappearance.editevent_spinnerbutton" />       </linearlayout>   </linearlayout> 

and related styles:

<style name="textappearance" parent="android:textappearance"> </style>  <style name="textappearance.editevent_spinner" parent="android:style/widget.holo.light.spinner">     <item name="android:textsize">14sp</item>     <item name="android:textcolor">#ff333333</item>     <item name="android:layout_marginright">12dp</item>     <item name="android:layout_marginleft">12dp</item> </style>  <style name="textappearance.editevent_spinnerbutton" parent="textappearance.editevent_spinner">     <item name="android:paddingleft">12dp</item>     <item name="android:paddingright">12dp</item> </style> 

set weightsum parent layout , divide weight sum value corresponding width of each child view.

try this

<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:layout_margintop="5dip"         android:animatelayoutchanges="false"         android:weightsum="2.5"         android:orientation="horizontal">          <textview             android:layout_width="0dp"             android:layout_height="match_parent"             android:gravity="center_vertical|center_horizontal"             android:paddingleft="10dp"             android:layout_weight=".5"             android:paddingtop="10dp"             android:text="from" />          <textview             android:id="@+id/start_date"             style="@style/textappearance.editevent_spinnerbutton"             android:layout_width="0dp"             android:layout_height="match_parent"             android:layout_marginright="0dp"             android:layout_weight="1.5"             android:contentdescription="start date"             android:paddingright="4dp"             android:paddingtop="15dp"             android:singleline="true"             android:text="10-11-2016" />          <textview             android:id="@+id/start_time"             style="@style/textappearance.editevent_spinnerbutton"             android:layout_width="0dp"             android:layout_height="match_parent"             android:layout_marginleft="0dip"             android:layout_weight=".5"             android:contentdescription="start time"             android:paddingtop="15dp"             android:text="13:58" />     </linearlayout>       <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_margintop="5dip"         android:weightsum="2.5"         android:animatelayoutchanges="false"         android:orientation="horizontal">           <textview             android:id="@+id/to_label"             android:layout_width="0dp"             android:layout_weight=".5"             android:layout_height="wrap_content"             android:gravity="center_vertical|center_horizontal"             android:paddingleft="10dp"             android:paddingtop="10dp"             android:text="to" />          <textview             android:id="@+id/end_date"             style="@style/textappearance.editevent_spinnerbutton"             android:layout_width="0dp"             android:layout_height="wrap_content"             android:layout_marginright="0dp"             android:layout_weight="1.5"             android:contentdescription="end date"             android:paddingright="4dp"             android:paddingtop="15dp"             android:singleline="true"             android:text="11-11-2016" />          <textview             android:id="@+id/end_time"             style="@style/textappearance.editevent_spinnerbutton"             android:layout_width="0dp"             android:layout_height="wrap_content"             android:layout_marginleft="0dip"             android:layout_weight=".5"             android:contentdescription="end time"             android:paddingtop="15dp"             android:text="23:59" />     </linearlayout> </linearlayout> 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -