Hel with a Activity design - android

I'm going crazy with a activity design
I think thah the problem is with the Weights atributes but I'm not sure. The fields of the row on middle contains letters hidding and the button size expands to height (not respond to changes in width and height atributes)
The span atributes is correctly assigned?
This is a snapshot of the activity
This is a summary of the estructure
LinearLayout 1
LinearLayout 1.1
TableLayout
TableRow
LinearLayout 1.2
TableLayout
TableRow con imagen centrada (span=4)
TableRow con 4 Textviews
TableRow con un textview que se modifica(span =2) y un boton de continuar (span=2)
LinearLayout 1.3
TextView
Wich effect have really the weight attribute in nested layouts?
This is the code of activity
<?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:background="#drawable/gradient"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp" >
<TableRow android:layout_gravity="center_vertical" >
<ImageView
android:id="#+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:contentDescription="#string/info_pm2"
android:src="#drawable/infomdpi2" />
<TextView
android:id="#+id/info_pm1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/pm3_3"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5"
android:gravity="center" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:background="#drawable/roundcorners"
android:gravity="center_horizontal"
android:paddingBottom="5dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="15dp" >
<TableRow
android:layout_weight="5"
android:gravity="center_vertical" >
<ImageView
android:id="#+id/instrtutpm1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="4"
android:layout_weight="1"
android:contentDescription="#string/logo"
android:paddingTop="5dp"
android:src="#drawable/t3_3" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_weight="1" >
<TextView
android:id="#+id/BtnOption0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|bottom"
android:text="A"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/BtnOption1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|bottom"
android:text="B"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/BtnOption2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|bottom"
android:text="C"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/BtnOption3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|bottom"
android:text="D"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="center_vertical|right" >
<TextView
android:id="#+id/respuesta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="3"
android:textStyle="bold" />
<Button
android:id="#+id/BtnNextQ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="4"
android:text="#string/next" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:gravity="center|right" >
<TextView
android:id="#+id/large_appname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/large_appname"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
Thanks a lot

Just remove android:layout_span="4" from Button Widget

In your code I observed the button has android:layout_span="4" If you remove this attribute for the button and for textview and make the TableRow to
<TableRow
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center_vertical|right" >
<TextView
android:id="#+id/respuesta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold" />
<Button
android:id="#+id/BtnNextQ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next" />
</TableRow>

// try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:background="#android:color/holo_blue_light"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:contentDescription="info_pm2"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/info_pm1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="pm3_3"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="25dp">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/instrtutpm1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="4"
android:contentDescription="logo"
android:paddingTop="5dp"
android:src="#drawable/ic_launcher" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" r>
<TextView
android:id="#+id/BtnOption0"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="A"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/BtnOption1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="B"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/BtnOption2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="C"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/BtnOption3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="D"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/respuesta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold" />
<Button
android:id="#+id/BtnNextQ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center|right" >
<TextView
android:id="#+id/large_appname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="large_appname"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>-->
</LinearLayout>

Related

adding a table layout in linear layout

I am trying to add a table inside a linear layout. Inside my linear layout there is textview, spinner. When I try to add a table layout it doesn't align correctly. Below is my code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/cardLayout"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product"
android:gravity="center"
android:textStyle="bold"
android:textSize="18sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:layout_margin="10sp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:orientation="vertical">
<Spinner
android:id="#+id/product_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
>
<TableRow android:background="#0079D6" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Product Name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Sale" />
</TableRow>
<TableRow android:background="#DAE8FC" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
Output
Expected Output
I must be missing something that I don't know. How can I align them equally just like in the above image
Any help would be highly appreciated.
Try using below code:
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product"
android:gravity="center"
android:textStyle="bold"
android:textSize="18sp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center">
<Spinner
android:id="#+id/product_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
/>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_gravity="center"
>
<TableRow android:background="#0079D6" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Product Name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Sale" />
</TableRow>
<TableRow android:background="#DAE8FC" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>

TableLayout columns are not of uniform width

Im trying to create a layout like following
Following is my code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:background="#drawable/border"
android:clipToPadding="false"
android:elevation="10dp"
android:orientation="vertical"
android:outlineProvider="bounds"
android:paddingBottom="10dp">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:orientation="horizontal"
android:stretchColumns="0,1,2">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:gravity="center_vertical"
android:text="Proforma Inv.#" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:gravity="center"
android:text="Invoice#" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:gravity="center_vertical"
android:text="Status" />
</TableRow>
</TableLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:orientation="horizontal"
android:stretchColumns="0,1,2">
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/dashProformaInvoiceNo"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PI1:4000039"
android:textColor="#00ff00"
android:textStyle="bold" />
<TextView
android:id="#+id/dashInvoiceNo"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="INC 4000039"
android:textStyle="bold" />
<TextView
android:id="#+id/dashShippingStatus"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cargo shipped"
android:textStyle="bold" />
</TableRow>
</TableLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:orientation="horizontal"
android:stretchColumns="*">
<TableRow
android:id="#+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:id="#+id/textView10"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Product:"
android:textStyle="bold" />
<TextView
android:id="#+id/dashProductName"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Biomass pellet"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:id="#+id/textView42"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rate: "
android:textStyle="bold" />
<TextView
android:id="#+id/dashRate"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="USD 100"
android:textStyle="bold" />
</LinearLayout>
</TableRow>
</TableLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:orientation="horizontal"
android:stretchColumns="*">
<TableRow
android:id="#+id/tableRow4"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:id="#+id/textView5"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ETD"
android:textStyle="bold" />
<TextView
android:id="#+id/dashETD"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="07 oct 2015 11.00"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:id="#+id/textView43"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quantitiy: "
android:textStyle="bold" />
<TextView
android:id="#+id/dashQuantity"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="600 Tons"
android:textStyle="bold" />
</LinearLayout>
</TableRow>
</TableLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:orientation="horizontal"
android:stretchColumns="*">
<TableRow
android:id="#+id/tableRow5"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView7"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ETA: "
android:textStyle="bold" />
<TextView
android:id="#+id/dashETA"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="06 OCT 2015"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView45"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Amount: "
android:textStyle="bold" />
<TextView
android:id="#+id/dashAmount"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="USD 6000"
android:textStyle="bold" />
</LinearLayout>
</TableRow>
</TableLayout>
</LinearLayout>
The problem is that Im not be able to make the columns to have equal width. I have tried setting weight to all linear layouts but still the problem persists.
try this,
TableLayout
android:stretchColumns="*" // Optionally use numbered list "0,1,2,3,..."
>
<TableRow
android:layout_width="0dp"
>
You are giving wrap content as layout width for textviews. This is interfering with stretch columns.
Change width of all elements inside table layout as
android:layout_width="0dp"
Also why are you using so many table layout? You can put all table row tags inside one table layout and the below can also come inside table layout inbetween table rows.
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_span="3"
android:background="#000" />
android:layout_span="3" will make the view span all the columns.
Try this *edited i mean textview
<TextView
android:layout_width="0dp"
android:layout_weight="1"
/>
LinearLayout width must be android:layout_width="0dp" when provide weight to any layout
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:id="#+id/textView5"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ETD"
android:textStyle="bold" />
<TextView
android:id="#+id/dashETD"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="07 oct 2015 11.00"
android:textStyle="bold" />
</LinearLayout>
I have solved it myself somehow
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:gravity="center_vertical"
android:text="Proforma Inv.#" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:gravity="center"
android:text="Invoice#" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:gravity="center_vertical"
android:text="Status" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/dashProformaInvoiceNo"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PI1:4000039"
android:textColor="#00ff00"
android:textStyle="bold" />
<TextView
android:id="#+id/dashInvoiceNo"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="INC 4000039"
android:textStyle="bold" />
<TextView
android:id="#+id/dashShippingStatus"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cargo shipped"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/textView10"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Product:"
android:textStyle="bold" />
<TextView
android:id="#+id/dashProductName"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Biomass pellet"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/textView42"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rate: "
android:textStyle="bold" />
<TextView
android:id="#+id/dashRate"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="USD 100"
android:textStyle="bold" />
</LinearLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/textView5"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ETD"
android:textStyle="bold" />
<TextView
android:id="#+id/dashETD"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="07 oct 2015 11.00"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/textView43"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quantitiy: "
android:textStyle="bold" />
<TextView
android:id="#+id/dashQuantity"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="600 Tons"
android:textStyle="bold" />
</LinearLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/textView7"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ETA: "
android:textStyle="bold" />
<TextView
android:id="#+id/dashETA"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="06 OCT 2015"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/textView45"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Amount: "
android:textStyle="bold" />
<TextView
android:id="#+id/dashAmount"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="USD 6000"
android:textStyle="bold" />
</LinearLayout>
</TableRow>
</TableLayout>

Contents in ListView not centered

My app retrieves user details from DB and displays in the ListView. However the contents displayed in the ListView are not formatted properly.
This is how my layout is currently rendered:
This is my layout file for the activity:
<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:background="#000000"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
tools:context=".LeaderBoard" >
<LinearLayout
android:id="#+id/column"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/column_header1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="#string/strLBoardHeaderRank"
android:textColor="#f00"
android:textSize="24sp" />
<TextView
android:id="#+id/column_header2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:text="#string/strLBoardHeaderName"
android:layout_gravity="center"
android:textColor="#f00"
android:textSize="24sp" />
<TextView
android:id="#+id/column_header3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="#string/strLBoardHeaderScore"
android:textColor="#f00"
android:textSize="24sp" />
</LinearLayout>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/column" >
</ListView>
</RelativeLayout>
The layout file for the list activity is below:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000" >
<TextView
android:id="#+id/rank"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:textColor="#f00"
android:textSize="20sp" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:textColor="#f00"
android:textSize="20sp" />
<TextView
android:id="#+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:textColor="#f00"
android:textSize="20sp" />
</LinearLayout>
add android:gravity="center" for all textviews and layout file for the list activity textviews width should be 0dp because of weight property and u should also add android:orientation="horizontal"
<TextView
android:id="#+id/column_header1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:gravity="center"
android:text="strLBoardHeaderRank"
android:textColor="#f00"
android:textSize="24sp" />
<TextView
android:id="#+id/column_header2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:gravity="center"
android:text="strLBoardHeaderName"
android:layout_gravity="center"
android:textColor="#f00"
android:textSize="24sp" />
<TextView
android:id="#+id/column_header3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:gravity="center"
android:text="strLBoardHeaderScore"
android:textColor="#f00"
android:textSize="24sp" />
layout file for the list
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="horizontal" >
<TextView
android:id="#+id/rank"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:gravity="center"
android:textColor="#f00"
android:textSize="20sp" />
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:gravity="center"
android:textColor="#f00"
android:textSize="20sp" />
<TextView
android:id="#+id/score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:gravity="center"
android:textColor="#f00"
android:textSize="20sp" />
</LinearLayout>
Try this one, this worked for me
//Main Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="horizontal" >
<TableLayout
android:id="#+id/add_rule_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_marginTop="5dp"
android:background="#color/list_divider"
android:orientation="vertical"
android:stretchColumns="*"
android:visibility="gone" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/list_divider"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/list_divider"
android:ems="4"
android:gravity="center"
android:text="#string/rule_no"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/list_divider"
android:ems="4"
android:gravity="center"
android:text="#string/lot"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/list_divider"
android:ems="4"
android:gravity="center"
android:text="#string/discount"
android:textSize="12sp"
android:textStyle="bold" />
</TableRow>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/list_divider" />
</TableLayout>
<ListView
android:id="#+id/rule_list_view"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_weight="1"
android:background="#android:color/transparent"
android:cacheColorHint="#00000000"
android:choiceMode="none"
android:listSelector="#android:color/transparent" />
</LinearLayout>
//Custom List View Items
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
>
<TableLayout
android:id="#+id/add_rule_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_marginTop="5dp"
android:background="#color/white"
android:orientation="vertical"
android:stretchColumns="*" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="horizontal" >
<TextView
android:id="#+id/rule_nos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginRight="1dp"
android:ems="3"
android:gravity="center_horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="1"
android:textSize="12sp" />
<TextView
android:id="#+id/lots"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="4"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="23"
android:textSize="12sp" />
<TextView
android:id="#+id/discount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="4"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="34%"
android:textSize="12sp" />
<TextView
android:id="#+id/edit_rule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/edit_rule"
android:ems="4"
android:gravity="center_horizontal"
android:text="#string/edit"
android:textColor="#ffffff"
android:textSize="12sp" />
<TextView
android:id="#+id/delete_rule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:background="#drawable/delete_rule"
android:ems="4"
android:gravity="center_horizontal"
android:text="#string/delete"
android:textColor="#ffffff"
android:textSize="12sp" />
</TableRow>
</TableLayout>
</LinearLayout>

Alignment problems with textview in android

I am building an app that is in 3 languages. The problem is that the text in textview is not aligning well. See image below -
I have set the gravity to start on all textviews.
I have tried Textview issue with text align, Android: Text in TextView not aligned well, How to align the textview to right in android?
The xml is as follows -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#F2D77C"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".AdActivity" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F2D77C"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F2D77C"
android:visibility="gone"
android:weightSum="2" >
<TextView
android:id="#+id/topCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#F2D77C"
android:paddingBottom="7dp"
android:paddingLeft="5dp" />
<TextView
android:id="#+id/topPrice"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="top|right|end"
android:layout_weight="1"
android:background="#F2D77C"
android:paddingRight="5dp"
android:textAlignment="textEnd"
android:textSize="20sp" />
</LinearLayout>
<!--
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
-->
<!-- </HorizontalScrollView> -->
<ImageSwitcher
android:id="#+id/imageSwitcher1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="400dp" >
</ImageSwitcher>
<Gallery
android:id="#+id/gallery1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:spacing="5dp" />
<TextView
android:id="#+id/textViewPrice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#F2D77C"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#262626" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Ad Code"
android:textStyle="bold"
android:textSize="20sp" />
<TextView
android:id="#+id/adCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Test code"
android:textSize="20sp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Viewed"
android:textStyle="bold"
android:textSize="20dp" />
<TextView
android:id="#+id/views"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="0"
android:textSize="20sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="4" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minWidth="50dp"
android:padding="5dp"
android:text="#string/city"
android:textColor="#5B554E"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/city"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="start"
android:padding="5dp"
android:textAlignment="gravity"
android:textColor="#FFFFFFFF"
android:textSize="20sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="4" >
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="#string/date"
android:textColor="#5B554E"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:gravity="start"
android:padding="5dp"
android:textAlignment="gravity"
android:textColor="#FFFFFFFF"
android:textSize="20sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="4" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="#string/price"
android:textColor="#5B554E"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/price"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:gravity="start"
android:padding="5dp"
android:textAlignment="gravity"
android:textColor="#FFFFFFFF"
android:textSize="20sp" />
</TableRow>
</TableLayout>
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#20202020"
android:padding="5dp"
android:text="#string/description"
android:textColor="#6B5F53"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#F2E0A7"
android:minHeight="75dp"
android:padding="5dp"
android:paddingBottom="10dp"
android:paddingTop="10dp" />
<TextView
android:id="#+id/textView10"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#20202020"
android:padding="5dp"
android:text="#string/publisher_details"
android:textColor="#6B5F53"
android:textSize="20sp" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp" >
<TableRow
android:padding="5dp"
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="#string/name"
android:textColor="#6B5F53"
android:textStyle="bold" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="TextView"
android:textColor="#999999" />
</TableRow>
</TableLayout>
<Button
android:id="#+id/buttonCallCar"
style="#drawable/button_wh"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_margin="2dp"
android:background="#drawable/button_bl"
android:paddingBottom="5dp"
android:text="Call" />
<Button
android:id="#+id/buttonAltCall"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_margin="2dp"
android:background="#drawable/button_bl"
android:text="Call" />
<Button
android:id="#+id/buttonFacebook"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_margin="2dp"
android:background="#drawable/button_bl"
android:drawableLeft="#drawable/facebook"
android:text="#string/share" />
</LinearLayout>
</ScrollView>
</LinearLayout>
The problem is occurring in Kurdish and Arabic but not in English(see image for English).

Get Layout XML to CustomView Layout

This is a Very simple layout I hope to achieve on. However, I tried many ways to make my customView appear at the side of the Buttons - LinearLayout. But I failed. Any help would be greatly appreciated!
Thank you!
This is where I declare my CustomView at MainActivity.
public class Drawing extends Activity {
mContent = (LinearLayout) findViewById(R.id.labelCreator);
mSignature = new Resize(this, null);
mContent.addView(mSignature);
...........
My XML Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:id="#+id/Drawing"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="visible" >
<LinearLayout
android:id="#+id/interface2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_marginTop="0dp"
android:background="#8b5a2b"
android:orientation="horizontal" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow9"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btnPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/camera2"
android:text="Camera"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="#+id/btnImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/image"
android:text="Image"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btnText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/text"
android:text="Text"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<EditText
android:id="#+id/editText1"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:ems="10"
android:freezesText="false"
android:hint="text"
android:maxLength="10"
android:maxLines="1"
android:textAlignment="center"
android:textColor="#e6e6fa"
android:textSize="25sp"
android:typeface="serif"
android:visibility="visible" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Spinner
android:id="#+id/color_spinner"
android:layout_width="135dp"
android:layout_height="wrap_content"
android:textAlignment="center" />
<Spinner
android:id="#+id/fonts_spinner"
android:layout_width="132dp"
android:layout_height="wrap_content"
android:textAlignment="center"
app:context=".LabelCreator" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/save3"
android:text="Save"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="#+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/clear"
android:text="Clear"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
</TableRow>
</TableLayout>
</TableRow>
<Button
android:id="#+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#drawable/close"
android:shadowColor="#00000000"
android:text="Close"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="#+id/btnAbout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="About"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
</TableLayout>
</LinearLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="250dp"
android:layout_height="85dp"
android:maxLines="1"
android:singleLine="true"
android:text="TextView"
android:textSize="20sp"
android:visibility="invisible" />
</LinearLayout>
This is just a structure to follow
<?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="10" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="3"
android:orientation="vertical" >
<Button
android:id="#+id/btnSave"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableTop="#drawable/save3"
android:text="Save"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="#+id/btnClear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableTop="#drawable/clear"
android:text="Clear"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Spinner
android:id="#+id/color_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAlignment="center" />
<Spinner
android:id="#+id/fonts_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
app:context=".LabelCreator" />
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="7" >
// your custom view(Drawing area) will be here.
</LinearLayout>
</LinearLayout>
Here the parent layout has android:orientation="horizontal" so all its child layout will display in column-wise.
If you want row-wise display make android:orientation="vertical". Here I use vertical for the parent layout that have <Button> and <Spinner> controls.
you will make changes in it as per your need.
Hope this will help.

Categories

Resources