i am having a simple tablelayout with the following view :
Fig 1 : When i add the button in the first column and give
android:layout_weight=1
to both buttons the fig 1 is the result.
Fig 2 : if i add the button in the second column then fig2 is the result.
my question is why the button is stretching to column3 when it is in column2 and why button in first column is not stretching to column2 in the second case.
In both case column 1 has been set to shrinkColumn as
android:shrinkColumns="1"
in the tablelayout in case it has any role in this.
xml file for the second case
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="1"
>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</TableRow>
<View android:background="#f00" android:layout_height="5dp"/>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"
/>
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_column="2"
android:layout_weight="1"
/>
</TableRow>
</TableLayout>
kindly update
From your question i can assume that you are trying to stretch the buttons equally in second row - Just add another table layout inside your current table layout
USE THE CODE:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*"
>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</TableRow>
<View android:background="#f00" android:layout_height="5dp"/>
</TableLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*"
>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
/>
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
/>
</TableRow>
</TableLayout>
Related
What i have is an android activity with xml style .. i have two radio box and two text view with auto complete text view , the thing is i made a style with table layout to order my layout and here is my xml :
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5sp"
android:paddingRight="7dp"
android:text="الرجاء اختيار اسم العميل "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="24sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:text="الصيدليات"
android:textSize="20sp" />
<RadioGroup
android:id="#+id/radiolang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- // here is error it says :The element type "RadioGroup" must be terminated by the matching end-tag "</RadioGroup>". -->
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<AutoCompleteTextView
android:id="#+id/txtsearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:text="العملاء"
android:textSize="20sp" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<AutoCompleteTextView
android:id="#+id/txtsearch2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:gravity="center_horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_marginTop="50sp"
android:background="#ff9900"
android:text="متابعة"
android:textSize="22sp" />
</TableRow>
</TableLayout>
And the thing is a have a table row before the other radio box , how can i fix it so my radio group control the two radio boxes?? without destroying my style?
Update your xml file with this code
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5sp"
android:text="الرجاء اختيار اسم العميل "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="24sp" />
</TableRow>
<RadioGroup
android:id="#+id/radiolang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:text="الصيدليات"
android:textSize="20sp" />
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<AutoCompleteTextView
android:id="#+id/txtsearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:text="العملاء"
android:textSize="20sp" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<AutoCompleteTextView
android:id="#+id/txtsearch2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
</TableRow>
</RadioGroup>
<TableRow
android:id="#+id/tableRow6"
android:gravity="center_horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_marginTop="50sp"
android:background="#ff9900"
android:text="متابعة"
android:textSize="22sp" />
</TableRow>
</TableLayout>
Try this one
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5sp"
android:paddingRight="7dp"
android:text="الرجاء اختيار اسم العميل "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="24sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:text="الصيدليات"
android:textSize="20sp" />
<RadioGroup
android:id="#+id/radiolang"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<AutoCompleteTextView
android:id="#+id/txtsearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:text="العملاء"
android:textSize="20sp" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioGroup>
</RadioGroup>
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<AutoCompleteTextView
android:id="#+id/txtsearch2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:gravity="center_horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_marginTop="50sp"
android:background="#ff9900"
android:text="متابعة"
android:textSize="22sp" />
</TableRow>
</TableLayout>
I want my image button to be placed on the rt side bottom of the scree. but it is not getting visible.Please see the code.
<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"
tools:context=".MainActivity" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date of Birth:" />
<Button
android:id="#+id/dateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:text="Select date" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Manual labour" />
<EditText
android:id="#+id/ed1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:inputType="number" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender :" />
<RadioGroup
android:id="#+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Male" />
<RadioButton
android:id="#+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Occupation" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/occuaption_arrays"
android:prompt="#string/occupation_prompt" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Monthly Income" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/income_arrays"
android:prompt="#string/income_prompt" />
</TableRow>
</TableLayout>
<ImageButton
android:id="#+id/next"
android:layout_height="50dp"
android:layout_width="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:contentDescription="dfg"
android:src="#drawable/next"
android:visibility="visible"/>
I have tried using RelativeLayout as parent and add attribute android:layout_alignParentRight="true" and android:layout_alignParentBottom="true"
My image is very large.Is that can be a problem?
You have setted match-parent to width and height of TableLayout. So TableLayout overlaps ImageButton
use below code...
android:layout_width="match_parent"
android:layout_height="wrap-content"
I have a LinearLayout with TableLayout and LinearLayout inside. TableLayout is made up of 5 TableRows. Each TableRow is made up of two View objects.
Firt column has two TextViews, my problem is that the text of TexView is wrapped:
The word SomeValue is wrapped, the letter e is a in new line, I'd like all in just one row, in this case and in general case, wath's the way pattern?
For example:
<?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"
android:orientation="vertical"
android:padding="#dimen/padding_small"
android:id="#+id/layout1">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|top"
android:stretchColumns="0,true"
android:shrinkColumns="*,true">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Value1"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Spinner
android:id="#+id/spinnerPrefix"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
**<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SomeValue"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/valueU"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" >
<requestFocus />
</EditText>
</TableRow>**
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Mytext"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
<EditText
android:id="#+id/valueN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AnyValue"
android:textAppearance="?android:attr/textAppearanceSmall" />
<DatePicker
android:id="#+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some"
android:textAppearance="?android:attr/textAppearanceSmall" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<RadioButton
android:id="#+id/radioM"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="M" />
<RadioButton
android:id="#+id/radioF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="F" />
</RadioGroup>
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="#dimen/padding_small" >
<Button
android:id="#+id/buttonRegistrazione"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Data" />
</LinearLayout>
</LinearLayout>
For each textview you could add
android:singleLine = "true"
That will make it a single line. If the text is too big then you could use ellipsize
android:ellipsize
to control how you want the text to appear
How to place TableLayout a grid of buttons 5 on 5 on the screen center?
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Table5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="30dp"
android:weightSum="5"/>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:background="#ffffff"
android:gravity="center" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b11" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b12" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b13" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b14" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b15" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b21" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b22" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b23" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b24" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b25" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b31" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="b32" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b33" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b34" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b35" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b41" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b42" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b43" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b44" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b45" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b51" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b52" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b53" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b54" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b55" />
</TableRow>
</TableLayout>
</RelativeLayout>
Use the above code in an android layout XML file to create your 5x5 button matrix using a TableLayout
<GridView
android:id="#+id/myGrid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="#dimen/grid_width"
android:gravity="center"
android:numColumns="auto_fit"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:stretchMode="spacingWidth"
android:verticalSpacing="8dp" />
and into grid_width, you can set a dimension (for hdpi, 480/5).
I don't know if this work for your situation. But try it
Try adding android:layout_gravity="center" attribute to the TableLayout
(If that doesn't work, wrap the TableLayout with a LinearLayout or something like that.)
I'm creating an android application, which has a particular screen (layout) with over (120+ views), which generates the warning:
"main.xml has more than 80 views, bad for performance"
I have lots of TextViews, EditTexts, groups of RadioButtons organized on 26 TableRows.
Is there anything I can do to enhance application performance and remove warning?
source:
main.xml_capture
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout00"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<TableRow
android:id="#+id/tableRow00"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:gravity="right" >
<Button
android:id="#+id/id_but_val"
android:layout_width="#dimen/button_width"
android:layout_height="wrap_content"
android:background="#drawable/button_colored"
android:text="#string/but_valid"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/id_but_up"
android:layout_width="#dimen/button_width"
android:layout_height="wrap_content"
android:background="#drawable/button_colored"
android:onClick="goToTop"
android:text="#string/but_ret_up"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/id_but_back"
android:layout_width="#dimen/button_width"
android:layout_height="wrap_content"
android:background="#drawable/button_colored"
android:text="#string/but_ret_back"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true"
android:overScrollMode="always"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideInset" >
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<TableRow
android:id="#+id/TableRow01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/row_margin_top" >
<TextView
android:id="#+id/TextView01"
android:layout_width="#dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:text="#string/ecran3_84_obstacles_acces" />
<RadioGroup
android:id="#+id/RadioGroup01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/RadioButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_value_oui" />
<RadioButton
android:id="#+id/RadioButton02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_value_non" />
</RadioGroup>
</TableRow>
<TableRow
android:id="#+id/TableRow02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/row_margin_top" >
<TextView
android:id="#+id/TextView02"
android:layout_width="#dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:text="#string/ecran3_85_limit_tonnage" />
<EditText
android:id="#+id/EditText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:ems="#string/editTextEms"
android:inputType="numberDecimal" />
</TableRow>
<TableRow
android:id="#+id/TableRow03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/row_margin_top"
android:visibility="gone" >
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:text="#string/ecran3_86_derog" />
</TableRow>
<TableRow
android:id="#+id/TableRow04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/row_margin_top" >
<TextView
android:id="#+id/TextView04"
android:layout_width="#dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:text="#string/ecran3_87_limit_hauteur" />
<EditText
android:id="#+id/EditText03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:ems="#string/editTextEms"
android:inputType="numberDecimal" />
</TableRow>
<TableRow
android:id="#+id/TableRow05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/row_margin_top" >
<TextView
android:id="#+id/TextView05"
android:layout_width="#dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:text="#string/ecran3_88_limit_largeur" />
<EditText
android:id="#+id/EditText04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:ems="#string/editTextEms"
android:inputType="numberDecimal" />
</TableRow>
<TableRow
android:id="#+id/TableRow06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/row_margin_top" >
<TextView
android:id="#+id/TextView06"
android:layout_width="#dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:text="#string/ecran3_89_trav_jour" />
<RadioGroup
android:id="#+id/RadioGroup06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/RadioButton11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_value_oui" />
<RadioButton
android:id="#+id/RadioButton12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_value_non" />
</RadioGroup>
</TableRow>
<TableRow
android:id="#+id/TableRow07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/row_margin_top" >
<TextView
android:id="#+id/TextView07"
android:layout_width="#dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:text="#string/ecran3_90_acces_intemperies" />
<RadioGroup
android:id="#+id/RadioGroup07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/RadioButton13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_value_oui" />
<RadioButton
android:id="#+id/RadioButton14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_value_non" />
</RadioGroup>
</TableRow>
<TableRow
android:id="#+id/TableRow08"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/row_margin_top" >
<TextView
android:id="#+id/TextView08"
android:layout_width="#dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:text="#string/ecran3_91_acces_de_client" />
<RadioGroup
android:id="#+id/RadioGroup08"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/RadioButton15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_value_oui" />
<RadioButton
android:id="#+id/RadioButton16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_value_non" />
</RadioGroup>
</TableRow>
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableRow
android:id="#+id/TableRow09"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/row_margin_top" >
<TextView
android:id="#+id/TextView09"
android:layout_width="#dimen/label_width"
android:layout_height="fill_parent"
android:layout_marginLeft="#dimen/view_left_margin"
android:text="#string/ecran3_92_contraintes_reservoir" />
<EditText
android:id="#+id/EditText05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:ems="#string/editTextEms"
android:inputType="text" />
</TableRow>
<TableRow
android:id="#+id/TableRow10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/row_margin_top" >
<TextView
android:id="#+id/TextView10"
android:layout_width="#dimen/label_width"
android:layout_height="fill_parent"
android:layout_marginLeft="#dimen/view_left_margin"
android:text="#string/ecran3_93_dalle_pret" />
<RadioGroup
android:id="#+id/RadioGroup10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/view_left_margin"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/RadioButton19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_value_oui" />
<RadioButton
android:id="#+id/RadioButton20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_value_non" />
</RadioGroup>
</TableRow>
<!-- TableRow10 to TableRow26 -->
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Without seeing your full layout I would say to replace that TableLayout with a ListView.
I'm guessing that you have a number of Views for each row, if you switch to a ListView you'll avoid the need to load the entire layout in memory, instead you'll load only the visible rows on the screen of the ListView + any views you have besides that.
With the above approach, you'll be able to remove a substantial number of rows from the current layout.
EDIT :
Based on your added layout, some advices:
TableRow can be used as a normal view in a layout but its main purpose it to be a child of a TableLayout.
If you don't want your Buttons from tableRow00 to have equal width then you can make a small improvement and instead of your current layout, replace LinearLayout00 with a RelativeLayout, remove the tableRow00 and then place the Buttons and the ScrollView using the rules of RelativeLayout.
Replace LinearLayout01 with a TableLayout.
I don't know why you added the LinearLayout02(I'm guessing all of your rows are the same?!) but you should remove it and directly append TableRow09 - TableRow26 to LinearLayout01.
The rest of my answer remains.