TableLayout width does not match RelativeLayout width - android

I am a beginner android programmer with a fair amount of Java background, mostly on a mainframe. (Yes it runs on a mainframe). I writing an app that tracks some daily activity, and after the default RealativeLayout I am adding a TableLayout via XML. In my onWindowFocusChanged I am also trying to set the width of the TableLayout. When I measure the two, the RelativeLayout is 1024, the screen size, but the TableLayout is 960. The XML and code snippet are below. Any help would be greatly appreciated as I have done many searches and a lot of Doc, and still can't get this to match.
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/WeekTbar"
android:stretchColumns="*"
android:shrinkColumns="*"
android:layout_alignParentLeft="true"
android:id="#+id/table"
android:background="#d4fbff">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0ff2D2Bf"
>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_column="0"
android:background="#2d2bff"
android:textColor="#ffffff"
android:text=" " />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_column="1"
android:text="Sun"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText3"
android:layout_column="2"
android:text="Mon"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText4"
android:layout_column="3"
android:text="Tue"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText6"
android:layout_column="4"
android:text="Wed"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText5"
android:layout_column="5"
android:text="Thu"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText8"
android:layout_column="6"
android:text="Fri"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText9"
android:layout_column="7"
android:text="Sat"
android:textColor="#ffffff"
android:background="#2d2bff" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0ff2D2Bf"
android:focusableInTouchMode="true">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText10"
android:layout_column="0"
android:text="Steps"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/SunSteps"
android:layout_column="1"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/MonSteps"
android:layout_column="2"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/TueSteps"
android:layout_column="3"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/WedSteps"
android:layout_column="4"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ThuSteps"
android:layout_column="5"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/FriSteps"
android:layout_column="6"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/SatSteps"
android:layout_column="7"
android:background="#2d2bff" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0ff2D2Bf">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText11"
android:layout_column="0"
android:text=Cals"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/SunCals"
android:layout_column="1"
android:focusableInTouchMode="true"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/MonCals"
android:layout_column="2"
android:textColor="#ffffff"
android:focusableInTouchMode="true"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/TueCals"
android:layout_column="3"
android:background="#2d2bff"
android:focusableInTouchMode="true"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/WedCals"
android:layout_column="4"
android:textColor="#ffffff"
android:focusableInTouchMode="true"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ThuCals"
android:layout_column="5"
android:background="#2d2bff"
android:focusableInTouchMode="true"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/FriCals"
android:layout_column="6"
android:textColor="#ffffff"
android:focusableInTouchMode="true"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText7"
android:layout_column="7"
android:background="#2d2bff"
android:focusableInTouchMode="true"
android:textColor="#ffffff" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0ff2D2Bf">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText12"
android:layout_column="0"
android:text="Wgt"
android:background="#2d2bff"
android:textColor="#ffffff" />
</TableRow>
</TableLayout>
Java code
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus == true) {
TableLayout table = (TableLayout) findViewById(R.id.table);
RelativeLayout rl = (RelativeLayout)findViewById(R.id.RelativeLayout);
int layoutWidth = rl.getWidth();
int layoutHeight = rl.getHeight();
table.getLayoutParams().width = layoutWidth;
table.setMinimumWidth(layoutWidth);
gw = table.getWidth();
rw = layoutWidth;
int x =1;
}
}

If you only want your table layout width match RelativeLayout width you shouldn't need to support multiple xml element.
Your problem maybe cause when you support android:padding in RelativeLayout or android:layout_margin in TableLayout.
Check the simple code below
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="10dp" // remove it
android:layout_height="match_parent" >
...
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
android:layout_margin="10dp" // remove it
>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
.... >
</TableRow>
....
</TableLayout>
</RelativeLayout>
See more about android layout margin and padding in this
Hope this help

Related

How to hide only part of layout when soft keyboard pops up

My layout is split into 3 sections (see screenshot). When the soft keyboard appears it partly hides section 1 and completely hides section 2. However, I need it to hide only section 2 and keep 1 and 3 fully visible. I tried using ScrollView as the outermost view but it leads to overlapping the section 3 when keyboard pops up instead of pushing it upwards. Can you suggest some solution on how to achieve this?
Layout code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/formWeHandelswareColor"
android:weightSum="10">
<TableLayout
android:id="#+id/Anlieferungkopf"
android:layout_width="match_parent"
android:layout_weight="2.5"
android:layout_height="0dp">
<TableRow
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_column="1"
android:textColor="#android:color/black"
android:text="Scan NVE"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextScanNve"
android:layout_column="2"
android:textColor="#android:color/black"
android:width="120dp"
android:layout_gravity="bottom"
android:layout_span="2"
android:singleLine="true"
android:textSize="14dip" />
<TextView
android:layout_column="4"
android:textColor="#android:color/black"
android:text="Ord. Lief."
android:layout_gravity="center_vertical"/>
<CheckBox
android:id="#+id/checkBoxAccepted"
android:layout_column="5"
android:layout_gravity="center_vertical"/>
<TextView
android:layout_column="6"
android:textColor="#android:color/black"
android:text="Platz"
android:layout_gravity="center_vertical"/>
<Spinner
android:id="#+id/spinnerPlace"
android:layout_column="7"
android:layout_gravity="center_vertical"/>
</TableRow>
<TableRow
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_column="1"
android:textColor="#android:color/black"
android:text="WE Nummer"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextReceiptNo"
android:layout_column="2"
android:layout_span="2"
android:textColor="#android:color/black"
android:layout_width="fill_parent"
android:layout_gravity="bottom"
android:singleLine="true"
android:textSize="14dip" />
<TextView
android:layout_column="4"
android:textColor="#android:color/black"
android:text="Lieferant"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextVendor"
android:enabled="false"
android:layout_column="5"
android:textColor="#android:color/black"
android:textSize="14dip"
android:layout_span="5"
android:width="120dp"
android:layout_gravity="bottom"
android:singleLine="true"/>
</TableRow>
<TableRow
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_column="1"
android:textColor="#android:color/black"
android:text="Bestellnummer"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextBestellnummer"
android:layout_column="2"
android:layout_width="150dip"
android:textColor="#android:color/black"
android:textSize="14dip"
android:layout_gravity="bottom"
android:singleLine="true"/>
<Button
android:id="#+id/btnAvisOrderNo"
android:layout_column="3"
android:text="->"/>
<TextView
android:layout_column="4"
android:textColor="#android:color/black"
android:text="LKW Temp.-Stat."
android:layout_gravity="center_vertical"/>
<CheckBox
android:id="#+id/checkBoxLkwTempStat"
android:layout_column="5"
android:layout_gravity="center_vertical"/>
<TextView
android:layout_column="6"
android:textColor="#android:color/black"
android:text="Temp. LKW"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextTempLKW"
android:layout_column="7"
android:textColor="#android:color/black"
android:width="120dp"
android:layout_gravity="bottom"
android:singleLine="true"
android:textSize="14dip" />
<TextView
android:layout_column="8"
android:textColor="#android:color/black"
android:text="Warentemp."
android:layout_gravity="center_vertical"/>
<EditText
android:layout_column="9"
android:id="#+id/editTextWarentemp"
android:width="120dp"
android:textColor="#android:color/black"
android:textSize="14dip"
android:singleLine="true"/>
</TableRow>
<TableRow
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_column="1"
android:textColor="#android:color/black"
android:text="Frachtführer"
android:layout_gravity="center_vertical"/>
<Spinner
android:id="#+id/spinnerCarrier"
android:layout_column="2"
android:layout_span="2"
android:layout_gravity="bottom"/>
<TextView
android:layout_column="4"
android:textColor="#android:color/black"
android:text="KFZ Kennz."
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextKfzKennz"
android:layout_column="5"
android:textColor="#android:color/black"
android:width="120dp"
android:singleLine="true"
android:textSize="14dip" />
<TextView
android:layout_column="6"
android:textColor="#android:color/black"
android:text="Fahrer"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextFahrer"
android:layout_column="7"
android:textColor="#android:color/black"
android:width="120dp"
android:singleLine="true"
android:textSize="14dip" />
</TableRow>
<TableRow
android:layout_height="0dp">
<Button
android:id="#+id/buttonCreateGoodsReceipt"
android:layout_column="1"
android:layout_span="3"
android:text="Wareneing. erstellen"/>
<Button
android:id="#+id/buttonFinishGoodsReceipt"
android:layout_column="4"
android:layout_span="3"
android:text="Wareneing. abschließen"/>
<Button
android:id="#+id/buttonCancelDelivery"
android:layout_column="7"
android:layout_span="3"
android:text="Anlieferung ablehnen"/>
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/Anliefungpos"
android:layout_width="match_parent"
android:layout_weight="3.5"
android:layout_height="0dp"
android:stretchColumns="*">
<!--Headers-->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="8">
<TextView
android:text="Artikel"
android:textSize="18dip"
android:textColor="#android:color/black"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:text="Benennung"
android:textSize="18dip"
android:textColor="#android:color/black"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:text="Menge Avis"
android:textSize="18dip"
android:textColor="#android:color/black"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:text="Einheit"
android:textSize="18dip"
android:textColor="#android:color/black"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:text="Menge gelief."
android:textSize="18dip"
android:textColor="#android:color/black"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:text="Anz. Pal."
android:textSize="18dip"
android:textColor="#android:color/black"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:text="NVE"
android:textSize="18dip"
android:textColor="#android:color/black"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:text="Status"
android:textSize="18dip"
android:textColor="#android:color/black"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</TableRow>
<ListView
android:listSelector="#drawable/ListViewRowSelector"
android:id="#+id/ListViewAnliefungPos"/>
</TableLayout>
<TableLayout
android:id="#+id/AnlieferungPositionLHM"
android:layout_width="match_parent"
android:layout_weight="4"
android:layout_height="0dp">
<TableRow
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_column="1"
android:textColor="#android:color/black"
android:text="Scan NVE/GS1"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextLhmScanNve"
android:layout_column="2"
android:width="250dp"
android:textColor="#android:color/black"
android:singleLine="true"
android:textSize="14dip" />
<Button
android:id="#+id/btnOpenScan"
android:layout_column="3"
android:text="Scan abschließen"
android:layout_gravity="center_vertical"/>
<TextView
android:layout_column="8"
android:textColor="#android:color/black"
android:text="Qualitätssicherung"
android:layout_gravity="top"/>
</TableRow>
<TableRow
android:layout_height="0dp"
android:layout_weight="1">
<EditText
android:id="#+id/editTextNotifications"
android:layout_column="1"
android:textColor="#android:color/black"
android:layout_height="wrap_content"
android:layout_span="7"
android:singleLine="true"
android:textSize="14dip" />
<TextView
android:layout_column="8"
android:textColor="#android:color/black"
android:text="Le defekt"
android:layout_gravity="center_vertical"/>
<CheckBox
android:id="#+id/checkBoxLeDefect"
android:layout_column="9"
android:layout_gravity="bottom"/>
</TableRow>
<TableRow
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:text="Artikel"
android:textColor="#android:color/black"
android:layout_width="0dp"
android:layout_column="1"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextItem"
android:textColor="#android:color/black"
android:layout_column="2"
android:singleLine="true"
android:textSize="14dip" />
<TextView
android:id="#+id/textViewItemDescr"
android:textColor="#android:color/black"
android:layout_column="3"
android:layout_span="5"
android:layout_gravity="center_vertical"/>
<TextView
android:text="Ordnungsstatus"
android:textColor="#android:color/black"
android:layout_column="8"
android:layout_gravity="center_vertical"/>
<CheckBox
android:id="#+id/checkBoxOrdnungsstatus"
android:layout_column="9"
android:layout_gravity="bottom"/>
</TableRow>
<TableRow
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_column="1"
android:textColor="#android:color/black"
android:text="Charge"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextCharge"
android:textColor="#android:color/black"
android:layout_column="2"
android:singleLine="true"
android:textSize="14dip" />
<TextView
android:layout_column="8"
android:textColor="#android:color/black"
android:text="Sauberkeitsstatus"
android:layout_gravity="center_vertical"/>
<CheckBox
android:id="#+id/checkBoxSauberkeitsstatus"
android:layout_column="9"
android:layout_gravity="bottom"/>
</TableRow>
<TableRow
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:text="MHD"
android:textColor="#android:color/black"
android:layout_column="1"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextMHD"
android:textColor="#android:color/black"
android:layout_column="2"
android:singleLine="true"
android:textSize="14dip" />
<TextView
android:text="Prod.-Datum"
android:textColor="#android:color/black"
android:layout_column="4"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextProdDate"
android:textColor="#android:color/black"
android:layout_column="5"
android:singleLine="true"
android:textSize="14dip" />
<TextView
android:layout_column="8"
android:textColor="#android:color/black"
android:text="Schädlingsstatus"
android:layout_gravity="center_vertical"/>
<CheckBox
android:id="#+id/checkBoxSchaedlingsstatus"
android:layout_column="9"
android:layout_gravity="bottom"/>
</TableRow>
<TableRow
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:text="Menge"
android:textColor="#android:color/black"
android:layout_column="1"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextMenge"
android:textColor="#android:color/black"
android:layout_column="2"
android:singleLine="true"
android:textSize="14dip" />
<TextView
android:textColor="#android:color/black"
android:layout_column="3"
android:layout_gravity="center_vertical"
android:id="#+id/textViewItemUom"/>
<TextView
android:text="Geometrie"
android:textColor="#android:color/black"
android:layout_column="4"
android:layout_gravity="center_vertical"/>
<Spinner
android:id="#+id/spinnerItemGeometry"
android:layout_column="5"
android:layout_width="150dp"
android:layout_gravity="center_vertical"/>
<TextView
android:layout_column="8"
android:textColor="#android:color/black"
android:text="Warentemp."
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextLhmWarentemp"
android:layout_column="9"
android:layout_width="50dip"
android:layout_gravity="center_vertical"
android:textColor="#android:color/black"
android:singleLine="true"
android:textSize="14dip" />
<TextView
android:layout_column="10"
android:textColor="#android:color/black"
android:text="Warentemp.-Status"
android:layout_gravity="center_vertical"/>
<CheckBox
android:id="#+id/checkBoxWarentempstatus"
android:layout_column="11"
android:layout_gravity="bottom"/>
</TableRow>
<TableRow
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:text="LHM-Nr."
android:textColor="#android:color/black"
android:layout_column="1"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/editTextLHMNr"
android:layout_gravity="center_vertical"
android:layout_column="2"
android:textColor="#android:color/black"
android:singleLine="true"
android:textSize="14dip" />
<TextView
android:text="LHM Typ"
android:textColor="#android:color/black"
android:layout_column="4"
android:layout_gravity="center_vertical"/>
<Spinner
android:id="#+id/spinnerLhmType"
android:layout_column="5"
android:layout_width="150dp"
android:layout_gravity="center_vertical"/>
<TextView
android:text="LHM Höhe"
android:textColor="#android:color/black"
android:layout_column="6"
android:layout_gravity="center_vertical"/>
<Spinner
android:id="#+id/spinnerLhmHeight"
android:layout_column="7"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"/>
<TextView
android:layout_column="8"
android:textColor="#android:color/black"
android:text="Altersstatus"
android:layout_gravity="center_vertical"/>
<CheckBox
android:id="#+id/checkBoxAltersstatus"
android:layout_column="9"
android:layout_gravity="bottom"/>
<TextView
android:layout_column="10"
android:textColor="#android:color/black"
android:text="Palettenstatus"
android:layout_gravity="center_vertical"/>
<CheckBox
android:id="#+id/checkBoxPalettenstatus"
android:layout_column="11"
android:layout_gravity="bottom"/>
</TableRow>
<TableRow
android:layout_height="0dp"
android:layout_weight="1">
<Button
android:id="#+id/btnPostLe"
android:layout_column="1"
android:text="LHM buchen"/>
<Button
android:id="#+id/btnWeCancel"
android:layout_column="2"
android:text="Abbrechen"/>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
Looks like you want to Resize your Activity when the SoftInput is showing.
So first, remove your outer ScrollView as you don't want to scroll everything.
Then on your Activity in the ActivityAttribute add a WindowSoftInputMode specification like:
[Activity(WindowSoftInputMode = SoftInput.AdjustResize | SoftInput.StateHidden)]
Now when the keyboard is showing, it should resize the Activity and your views.
Try to check if the keyboard is open and use VISIBILITY / GONE.
aktivityMainRelativLayout = (RelativeLayout)findViewById(R.id.main);
aktivityMainRelativLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int heightDiff = aktivityMainRelativLayout.getRootView().getHeight() - aktivityMainRelativLayout.getHeight();
if (heightDiff > 100) {
//keyboard open
anliefungposLayout.setVisibility(View.GONE);
} else {
//keyboard close
anliefungposLayout.setVisibility(View.VISIBLE);
}
}
});

How to make this android layout more 'responsive'?

I have an android layout with some title bar and some input fields, and when I try to input some values, I can do it, but
the title bar vanishes
If I want to edit the field "Another number" I cannot scroll down to use the SeekBar instead.
How can I change the layout to make it
Have the title bar (with the text "InputExample") always fixes
Have the other content of the screen scrollable (so that I can use the SeekBar, for example)?
The layout is here:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc"
android:layout_marginBottom = "0dp">
<GridLayout
android:id="#+id/grid"
android:layout_margin="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#+id/new_cancel"
android:alignmentMode="alignBounds"
android:columnCount="10"
android:columnOrderPreserved="false"
android:useDefaultMargins="true">
<TextView
android:id="#+id/textTitleEdit"
android:layout_column="0"
android:layout_columnSpan="10"
android:layout_gravity="center_horizontal"
android:layout_row="0"
android:text="My Title"
android:textSize="32dip"/>
<TextView
android:text="You can enter some values"
android:textSize="16dip"
android:layout_columnSpan="8"
android:layout_gravity="left"
android:id="#+id/textSubTitleEdit"
android:layout_row="1"
android:layout_column="0" />
<TextView
android:text="Name"
android:layout_gravity="right"
android:layout_row="2"
android:layout_column="0"
/>
<EditText
android:ems="7"
android:singleLine="true"
android:inputType="textCapWords"
android:id="#+id/new_name"
android:layout_row="2"
android:layout_column="1" />
_____________
<TextView
android:text="Label"
android:layout_gravity="right"
android:layout_row="3"
android:layout_column="0" />
<EditText
android:ems="7"
android:singleLine="true"
android:inputType="textCapWords"
android:id="#+id/new_label"
android:layout_row="3"
android:layout_column="1" />
______
<TextView
android:layout_column="0"
android:text="Put in a number"
android:layout_gravity="right"
/>
<EditText
android:ems="7"
android:singleLine="true"
android:id="#+id/new_price"
android:inputType="numberDecimal"
android:layout_row="4"
android:layout_column="1" />
<TextView
android:layout_column="0"
android:text="Another number"
android:layout_gravity="right"
android:layout_row="5" />
<EditText
android:ems="7"
android:singleLine="true"
android:id="#+id/new_offset"
android:inputType="number"
android:layout_row="5"
android:layout_column="1" />
<SeekBar
android:id="#+id/seek_offset"
style="#android:style/Widget.Holo.SeekBar"
android:layout_width="150dp"
android:layout_column="1"
android:layout_row="6"
android:max="20"/>
<TextView
android:text="Comment"
android:layout_gravity="right"
android:layout_row="7"
android:layout_column="0" />
<EditText
android:ems="7"
android:singleLine="true"
android:inputType="textCapWords"
android:id="#+id/new_comment"
android:layout_row="7"
android:layout_column="1" />
</GridLayout>
<Button
android:id="#+id/new_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#aaaaaa"
android:text="Cancel"
android:layout_margin="5dp"
/>
<Button
android:id="#+id/new_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:background="#dddddd"
android:text="Ok"
android:layout_margin="5dp"
/>
</RelativeLayout>
</FrameLayout>
Was having some problems with your original layout so I've fixed it up and I think this solution should work. Everything in the preview of the layout has it positioned correctly so hopefully when you use this in the emulator it should work.
I personally prefer using LinearLayouts with weights for the majority of my layouts, I know some others prefer RelativeLayouts.
Essentially you should look to contain the part which you wish to scroll with a layout of some kind and then the ScrollView contains this layout so it can be scrolled. This is why I've removed the title and subtitle from the GridLayout.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc"
android:weightSum="6">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.5"
android:orientation="vertical"
android:gravity="bottom|center_horizontal">
<TextView
android:id="#+id/textTitleEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="My Title"
android:textSize="32dip"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You can enter some values"
android:textSize="16dip"
android:layout_gravity="center_horizontal"
android:id="#+id/textSubTitleEdit"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<GridLayout
android:id="#+id/grid"
android:layout_margin="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alignmentMode="alignBounds"
android:columnCount="10"
android:columnOrderPreserved="false"
android:useDefaultMargins="true">
<TextView
android:text="Name"
android:layout_gravity="right"
android:layout_row="2"
android:layout_column="0"/>
<EditText
android:ems="7"
android:singleLine="true"
android:inputType="textCapWords"
android:id="#+id/new_name"
android:layout_row="2"
android:layout_column="1"/>
<TextView
android:text="Label"
android:layout_gravity="right"
android:layout_row="3"
android:layout_column="0"/>
<EditText
android:ems="7"
android:singleLine="true"
android:inputType="textCapWords"
android:id="#+id/new_label"
android:layout_row="3"
android:layout_column="1" />
<TextView
android:layout_column="0"
android:text="Put in a number"
android:layout_gravity="right"
/>
<EditText
android:ems="7"
android:singleLine="true"
android:id="#+id/new_price"
android:inputType="numberDecimal"
android:layout_row="4"
android:layout_column="1" />
<TextView
android:layout_column="0"
android:text="Another number"
android:layout_gravity="end"
android:layout_row="5" />
<EditText
android:ems="7"
android:singleLine="true"
android:id="#+id/new_offset"
android:inputType="number"
android:layout_row="5"
android:layout_column="1" />
<SeekBar
android:id="#+id/seek_offset"
style="#android:style/Widget.Holo.SeekBar"
android:layout_width="150dp"
android:layout_column="1"
android:layout_row="6"
android:max="20"/>
<TextView
android:text="Comment"
android:layout_gravity="right"
android:layout_row="7"
android:layout_column="0" />
<EditText
android:ems="7"
android:singleLine="true"
android:inputType="textCapWords"
android:id="#+id/new_comment"
android:layout_row="7"
android:layout_column="1" />
</GridLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.5"
android:gravity="bottom|center_horizontal"
android:weightSum="2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:layout_weight="1">
<Button
android:id="#+id/new_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity=""
android:background="#aaaaaa"
android:text="Cancel"
android:layout_margin="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:layout_weight="1">
<Button
android:id="#+id/new_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#dddddd"
android:text="Ok"
android:layout_margin="5dp"/>
</RelativeLayout>
</LinearLayout>

EditText disapear if layout_width="wrap_content" and not layout_weight="1"

The next code is OK for Eclipse Layout Editor and Android Studio. I tested it in several mobiles and works fine but, in a Samsung GT-S6310N (Android 4.1.2), this EditText dissapears. It goes at the end of a LinearLayout that defines the Layout width. The Layout is showed in a Dialog using android:Theme.Dialog.
<EditText
android:id="#+id/et_clino"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="4"
android:inputType="numberDecimal"
android:text="89.9" />
I've solved this changing the code to:
<EditText
android:id="#+id/et_clino"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="4"
android:inputType="numberDecimal"
android:text="89.9" />
The question is: is wrong mi code or is a bug?
This is the code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
tools:context=".Measure" >
<RelativeLayout
android:id="#+id/rl_a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBaseline="#+id/et_from"
android:text="#string/from"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/et_from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/TextView1"
android:ems="7"
android:hint="#string/from"
android:lines="1"
android:maxLength="7"
android:minLines="1"
android:nextFocusDown="#+id/et_to"
android:text="1234567" />
<EditText
android:id="#+id/et_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/et_from"
android:layout_alignParentRight="true"
android:ems="7"
android:hint="#string/to"
android:maxLength="7"
android:maxLines="1"
android:nextFocusDown="#+id/et_distance"
android:text="1234567" />
<TextView
android:id="#+id/TextView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/et_from"
android:layout_toLeftOf="#+id/et_to"
android:text="#string/to"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<LinearLayout
android:id="#+id/ll_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tv_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/distance_abr"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/green" />
<EditText
android:id="#+id/et_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="4"
android:hint="#string/distance_abr"
android:inputType="numberDecimal"
android:lines="5"
android:maxLength="6"
android:nextFocusDown="#+id/et_rumbomag" />
<TextView
android:id="#+id/TextView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rumbo_mn_abr"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/et_rumbomag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="4"
android:hint="#string/rumbo_mn_abr"
android:inputType="numberDecimal"
android:maxLength="5"
android:nextFocusDown="#+id/et_measured_clino"
android:text="360.0" />
<TextView
android:id="#+id/tv_clino"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/clino"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/et_clino"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="4"
android:inputType="numberDecimal"
android:text="89.9" />
<!-- Así produce error: el et_clino desaparece y el tv_clino se estrecha y muestra el texto en 3 líneas
<EditText
android:id="#+id/et_clino"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="4"
android:inputType="numberDecimal"
android:text="89.9" />
-->
</LinearLayout>
<LinearLayout
android:id="#+id/ll_d"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioGroup
android:id="#+id/rg_direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/rb_direct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:hint="#string/direction"
android:text="#string/direct" />
<RadioButton
android:id="#+id/rb_inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/inverse" />
</RadioGroup>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" >
<!--
<Button
android:id="#+id/btn_get_from_bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BT"
android:textColor="#color/blue" />
-->
<Button
android:id="#+id/btn_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="#string/delete"
android:textColor="#color/red" />
<ImageButton
android:id="#+id/ib_disto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#drawable/disto" />
<Button
android:id="#+id/btn_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="#string/save"
android:textColor="#color/green" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_e"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/et_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/description" >
<requestFocus />
</EditText>
</LinearLayout>
I've made some changes (particularly the LinearLayout containing the cli_no EditText, #string and #drawable resources) in the xml file as below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/rl_a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/et_from"
android:layout_alignParentLeft="true"
android:text="#string/from"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/et_from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/TextView1"
android:ems="7"
android:hint="#string/from"
android:lines="1"
android:maxLength="7"
android:minLines="1"
android:nextFocusDown="#+id/et_to"
android:text="1234567" />
<EditText
android:id="#+id/et_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/et_from"
android:layout_alignParentRight="true"
android:ems="7"
android:hint="#string/to"
android:maxLength="7"
android:maxLines="1"
android:nextFocusDown="#+id/et_distance"
android:text="1234567" />
<TextView
android:id="#+id/TextView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/et_from"
android:layout_toLeftOf="#+id/et_to"
android:text="#string/to"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<LinearLayout
android:id="#+id/ll_b"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tv_distance"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="distance_abr"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/green" />
<EditText
android:id="#+id/et_distance"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ems="4"
android:layout_weight="1"
android:hint="distance_abr"
android:inputType="numberDecimal"
android:lines="5"
android:maxLength="6"
android:nextFocusDown="#+id/et_rumbomag" />
<TextView
android:id="#+id/TextView3"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="distance_abr"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/et_rumbomag"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:ems="4"
android:hint="rumbo"
android:inputType="numberDecimal"
android:maxLength="5"
android:text="360.0" />
<TextView
android:id="#+id/tv_clino"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="clino"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/et_clino"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="4"
android:inputType="numberDecimal"
android:text="89.9" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_d"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioGroup
android:id="#+id/rg_direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/rb_direct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:hint="direction"
android:text="direct" />
<RadioButton
android:id="#+id/rb_inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="inverse" />
</RadioGroup>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" >
<!--
<Button
android:id="#+id/btn_get_from_bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BT"
android:textColor="#color/blue" />
-->
<Button
android:id="#+id/btn_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="#string/delete" />
<ImageButton
android:id="#+id/ib_disto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#drawable/back02" />
<Button
android:id="#+id/btn_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="save"
android:textColor="#color/green" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_e"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/et_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/description" >
<requestFocus />
</EditText>
</LinearLayout>
The reason for disappearing of the EditText is that you want to display items, which has total width greater than the width of the screen, so I've applied same layout_weight:"1" to all the elements inside the LinearLayout. May be this helps you for solving your issue.

Achieving the same result without paddingLeft property

<?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="wrap_content"
android:orientation="vertical"
android:padding="5dip" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:padding="1dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="20dp"
android:text="Total Pregnancies"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="30dp"
android:text="10"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="160dp"
android:text="Full Term"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="75dp"
android:text="11"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="190dp"
android:text="Premature"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="30dp"
android:text="12"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_below="#+id/linearLayout1"
android:layout_marginTop="35dp"
android:padding="1dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="20dp"
android:text="Multiples"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="85dp"
android:text="16"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="160dp"
android:text="Living"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="95dp"
android:text="17"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_centerVertical="true"
android:padding="1dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="20dp"
android:text="Ab Included"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="70dp"
android:text="13"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="160dp"
android:text="Ab Spontaneous"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="30dp"
android:text="14"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="190dp"
android:text="Ectopics"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="35dp"
android:text="15"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
This is how the screen looks, can anyone tell me how can i achieve this layout. i have come up with the layout, but it seems it does not fit for all screens.
Make the LinearLayout width fill_parent to use the entire width of the screen.
Then for each TextView, set the layout_width to 0dp, and set layout_weight to the proportion of the screen you want that view to have.
In the padding, specify the minimum amount you want between the different cells.
For example, if you want the text to occupy double the space of the numbers, use the following code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dip" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:padding="1dip" >
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="Total Pregnancies"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="10"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="Full Term"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="11"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="Premature"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="12"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
Use TableLayout
Here is an example

How to make table rows scrollable in android

Below given is my layout which is I am using for displaying a table, which have a number of rows. the problem is this table have more no of rows than the screen can contain, so i want rows to be scrollable so that if i scroll down i can reach to the rows which is not visible in current screen.
i used isScrollContainer="true" bur this does not solve my problem
Can you please suggest which property can i use to solve the problem
<TableLayout android:layout_height="wrap_content" android:isScrollContainer="true" >
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:gravity="center">
<View android:layout_gravity="center" android:layout_height="30px"
android:background="#android:color/darker_gray"
android:layout_width="400px" />
<TextView android:layout_width="wrap_content" style="#style/styleName"
android:id="#+id/tv_add_ticket" android:text="Update Ticket on Assembloid Space"
android:layout_height="wrap_content" android:layout_marginLeft="5px"
android:layout_marginRight="2px" android:layout_marginTop="2px"
android:layout_marginBottom="2px">
</TextView>
</RelativeLayout>
</TableLayout>
<TableLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20px" android:isScrollContainer="true"
xmlns:android="http://schemas.android.com/apk/res/android"
android:baselineAligned="true" android:background="#565051"
android:layout_marginTop="50px">
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/ticket_status"
android:text="Status " android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
<!-- <EditText android:layout_width="250px" android:layout_height="wrap_content"
android:id="#+id/et_ticket_status"></EditText> -->
<Spinner android:layout_width="100px" android:layout_height="wrap_content"
android:id="#+id/spn_up_ticket_status"></Spinner>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/ticket_priority"
android:text="Priority" android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
<Spinner android:layout_width="200px" android:layout_height="wrap_content"
android:id="#+id/spn_up_ticket_priority"></Spinner>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/ticket_summary"
android:text="Summary" android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
/>
<EditText android:layout_width="250px" android:id="#+id/et_ticket_summary"
android:layout_height="wrap_content" android:autoText="true">
</EditText>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/ticket_discription"
android:text="Discription" android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
/>
<EditText android:layout_width="250px" android:id="#+id/et_ticket_Discription"
android:layout_height="wrap_content" android:autoText="true"></EditText>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/estimated_hour"
android:text="Estimated Hours" android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
/>
<EditText android:layout_width="250px" android:id="#+id/et_estimated_hour"
android:layout_height="wrap_content" android:autoText="true"></EditText>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/worked_hour"
android:text="Worked Hours" android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
<EditText android:layout_width="250px" android:id="#+id/et_worked_hour"
android:layout_height="wrap_content" android:autoText="true"></EditText>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/ticket_comment"
android:text="Comment" android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
/>
<EditText android:layout_width="250px" android:id="#+id/et_ticket_comment"
android:layout_height="wrap_content" android:autoText="true">
</EditText>
</TableRow>
<TableRow>
<Button android:layout_width="wrap_content" android:text="Comments"
android:layout_height="wrap_content" android:id="#+id/comment_ticket_button" android:layout_column="1" ></Button>
<Button android:layout_width="wrap_content" android:text="#string/update_ticket"
android:layout_height="wrap_content" android:id="#+id/update_ticket_button" android:layout_column="3"></Button>
</TableRow>
<TextView android:id="#+id/error_ticket_text"
android:layout_centerHorizontal="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="#+id/login_button" />
You should wrap your TableLayout inside a ScrollView with appropriate height
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="100dp">
<TableLayout..>
</TableLayout>
</ScrollView>
You should use ScrollView as the root layout to solve your problem.

Categories

Resources