I have two layouts, one is the main layout inside which I am including my custom keypad layout. When ever I hide the included layout, the main layout gets distorted.
My main layout xml is as follows.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_rl"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient_header" >
<LinearLayout
android:id="@+id/linHeader"
style="@style/linHeader"
android:layout_height="55dp"
android:baselineAligned="false"
android:weightSum="1" >
<LinearLayout
android:id="@+id/linLogo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".60"
android:gravity="center_vertical" >
<TextView
android:id="@+id/tvOutletName"
style="@style/linHeader_text"
android:text="" >
</TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".40"
android:gravity="right|center_vertical" >
<LinearLayout
android:id="@+id/btnAdvList"
style="@style/btnChart"
android:onClick="btnAdvList" >
</LinearLayout>
<LinearLayout
android:id="@+id/btnDownArrow"
style="@style/btnDownArrow"
android:onClick="btnCollapseExpand" >
</LinearLayout>
<LinearLayout
android:id="@+id/btnRightArrow"
style="@style/btnRightArrow"
android:onClick="btnDone" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/linSearch"
style="@style/linSearch"
android:layout_below="@+id/linHeader" >
<EditText
android:id="@+id/etSearchText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:hint="@string/LblText_Search" />
</LinearLayout>
<LinearLayout
android:id="@+id/linInfo"
style="@style/linInfo"
android:layout_below="@+id/linSearch" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</Spinner>
<Spinner
android:id="@+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</Spinner>
<Spinner
android:id="@+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</Spinner>
</LinearLayout>
<LinearLayout
android:id="@+id/linTitle"
style="@style/lstTitle"
android:layout_below="@+id/linInfo" >
<TextView
android:id="@+id/tvItems"
style="@style/lstTitleText"
android:layout_width="0dp"
android:layout_weight="2"
android:text="@string/LblText_Items" >
</TextView>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/lsttitle_seperator" >
</ImageView>
<TextView
android:id="@+id/tvOrder"
style="@style/lstTitleText"
android:layout_width="0dp"
android:layout_weight="1"
android:text="@string/AdvList_Order" >
</TextView>
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/lsttitle_seperator" >
</ImageView>
<TextView
android:id="@+id/tvTotal"
style="@style/lstTitleText_Right"
android:layout_width="0dp"
android:layout_weight="1"
android:text="@string/AdvList_Total" >
</TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/linBody"
style="@style/linBody"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="@+id/linKeypad"
android:layout_below="@+id/linTitle"
android:orientation="vertical"
android:weightSum="1" >
<ExpandableListView
android:id="@+id/expandableList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:childDivider="#fff"
android:focusable="true"
android:groupIndicator="@android:color/transparent" >
</ExpandableListView>
</LinearLayout>
<LinearLayout
android:id="@+id/linKeypad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/linFooter" >
<include
android:id="@+id/linearLayoutKeyPad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/custom_decimal_keypad" />
</LinearLayout>
<LinearLayout
android:id="@+id/linFooter"
style="@style/linFooter" >
<TextView
android:id="@+id/tvOrdersTaken"
style="@style/linFooter_text"
android:layout_weight="1" >
</TextView>
<TextView
android:id="@+id/tvTotalValue"
style="@style/linFooter_text"
android:layout_weight="1"
android:gravity="right" >
</TextView>
</LinearLayout>
</RelativeLayout>
and the included keypad layout is as follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayoutKeyPad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#efefef"
android:orientation="vertical"
>
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#999"
android:gravity="center_horizontal" >
<Button
android:id="@+id/btnKeyPad0"
android:layout_width="40dip"
android:onClick="btnKeyPad0"
android:text="0" >
</Button>
<Button
android:id="@+id/btnKeyPad1"
android:layout_width="40dip"
android:onClick="btnKeyPad1"
android:text="1" >
</Button>
<Button
android:id="@+id/btnKeyPad2"
android:layout_width="40dip"
android:onClick="btnKeyPad2"
android:text="2" >
</Button>
<Button
android:id="@+id/btnKeyPad3"
android:layout_width="40dip"
android:onClick="btnKeyPad3"
android:text="3" >
</Button>
<Button
android:id="@+id/btnKeyPad4"
android:layout_width="40dip"
android:onClick="btnKeyPad4"
android:text="4" >
</Button>
<ImageButton
android:id="@+id/btnKeyPadBackSpace"
android:layout_width="40dip"
android:onClick="btnKeyPadBackSpace"
android:src="@drawable/backspace" >
</ImageButton>
</TableRow>
</TableLayout>
<TableLayout
android:id="@+id/tableLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#999"
android:gravity="center_horizontal" >
<Button
android:id="@+id/btnKeyPad5"
android:layout_width="40dip"
android:onClick="btnKeyPad5"
android:text="5" >
</Button>
<Button
android:id="@+id/btnKeyPad6"
android:layout_width="40dip"
android:onClick="btnKeyPad6"
android:text="6" >
</Button>
<Button
android:id="@+id/btnKeyPad7"
android:layout_width="40dip"
android:onClick="btnKeyPad7"
android:text="7" >
</Button>
<Button
android:id="@+id/btnKeyPad8"
android:layout_width="40dip"
android:onClick="btnKeyPad8"
android:text="8" >
</Button>
<Button
android:id="@+id/btnKeyPad9"
android:layout_width="40dip"
android:onClick="btnKeyPad9"
android:text="9" >
</Button>
<Button
android:id="@+id/btnKeyPadDecimal"
android:layout_width="40dip"
android:onClick="btnKeyPadDecimal"
android:text="." >
</Button>
<Button
android:id="@+id/btnKeyPadOk"
android:layout_width="43dip"
android:onClick="btnKeyPadOk"
android:text="@string/LblText_Ok" >
</Button>
</TableRow>
</TableLayout>
</LinearLayout>
The expandable listview row layout is :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linOrderTakingList"
style="@style/lstRow" >
<TextView
android:id="@+id/tvItemDesc"
style="@style/lstRowText"
android:layout_width="0dp"
android:layout_weight="2" >
</TextView>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/lsttitle_seperator" >
</ImageView>
<TextView
android:id="@+id/tvOrderQty"
style="@style/lstRowText"
android:layout_width="0dp"
android:layout_weight="1" >
</TextView>
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/lsttitle_seperator" >
</ImageView>
<TextView
android:id="@+id/tvOrderValue"
style="@style/lstRowText_Right"
android:layout_width="0dp"
android:layout_weight="1" >
</TextView>
</LinearLayout>
The expandable listview child layout is :
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
style="@style/lstRow_Expanded_1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/btnUnit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="@string/LblText_Unit" >
</Button>
<Button
android:id="@+id/btnCopy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="@string/MenuBtnText_Copy" >
</Button>
<TextView
android:id="@+id/tvQty"
style="@style/txtLable"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="right"
android:text="@string/AdvList_Qty" >
</TextView>
<TextView
android:id="@+id/tvQtyValue"
style="@android:style/Widget.EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2" >
<requestFocus />
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tvAvg"
style="@style/txtLable"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="@string/LblText_Avg" >
</TextView>
<TextView
android:id="@+id/tvLag"
style="@style/txtLable"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="@string/LblText_Lag" >
</TextView>
<TextView
android:id="@+id/tvUnitPr"
style="@style/txtLable"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="@string/LblText_Unit_Pr" >
</TextView>
<TextView
android:id="@+id/tvMrp"
style="@style/txtLable"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="@string/LblText_MRP" >
</TextView>
<TextView
android:id="@+id/tvSo"
style="@style/txtLable"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="@string/LblText_SO" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tvAvgValue"
style="@android:style/Widget.EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/tvLagValue"
style="@android:style/Widget.EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/tvUnitPrValue"
style="@android:style/Widget.EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/tvMrpValue"
style="@android:style/Widget.EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/tvSoValue"
style="@android:style/Widget.EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</TableRow>
</TableLayout>
The screenshot of the layout before viewing the keypad :
and the screenshot of the distorted layout after making keypad visible :
I also tried to refresh the child view, invalidate the view, programatically modify the relative layout. Please help me with some solutions. If I don't put the list above the keypad, it doesn't distort, but the list view gets hidden behind the keypad which is not useful. I basically need the keypad to push the list view up when it gets visible and back to normal when it is gone.
Since the distortion happens to the expanded view, the problem is probably in its layout.
I'd suggest you get rid of TableLayout
in your child layout: it is sometimes unpredictable and the same result may be achieved without it (using nested LinearLayout
's, for example).