How to Dock a control in Monodroid? - c#

I want to dock the image-button (btn_add) to bottom of the activity.
I found couple of similar questions on there but they were useless for me.
Because of the way I used Scroll & Linear & Relative layout.
(Actually I can't set a relative-layout as the main layout of my activity as they said)
How can I do it ?
Please help!
My activity :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="Count"
android:gravity="right"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textView3" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="Question Count"
android:gravity="right"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textView3" />
<EditText
android:inputType="text"
android:layout_width="65.0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:id="#+id/txt_totalCount"
android:text="" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="True Count"
android:gravity="right"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textView3" />
<EditText
android:inputType="text"
android:layout_width="65.0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:id="#+id/txt_trueCount"
android:text="" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="False Count"
android:gravity="right"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textView3" />
<EditText
android:inputType="text"
android:layout_width="65.0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:id="#+id/txt_falseCount"
android:text="" />
<TextView
android:text="Num"
android:gravity="right"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textView3" />
<EditText
android:inputType="text"
android:layout_width="65.0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:id="#+id/txt_number"
android:text="" />
</RelativeLayout>
<RadioGroup
android:gravity="right"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/rdoGroup">
<TextView
android:text="Has Negative"
android:gravity="right"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Yeah"
android:gravity="right"
android:id="#+id/rdo_true"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nope"
android:gravity="right"
android:id="#+id/rdo_false"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RadioGroup>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="Percent"
android:gravity="right"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textView4" />
<EditText
android:inputType="text"
android:layout_width="65.0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:id="#+id/txt_percent"
android:text="" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<ImageButton
android:src="#drawable/create_icon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="#+id/btn_add" />
</RelativeLayout>
</LinearLayout>
</ScrollView>

You should set the property "FillViewPort" on the scrollview on true. Like this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
That should do the trick!

Related

Layout is not going to the bottom! It's on the side

When I create a new Layout, it is appearing on the right side of the screen. I want it to be at the bottom, below my linear layout. Example in the picture.
LayoutPicture
Do you want to achieve result like following GIF?
if so, you can add the android:gravity="bottom" in the outside LinearLayout, here is my layout xml(If you want layout to the bottom-center, you can use android:gravity="bottom|center").
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
>
<LinearLayout
android:layout_width="200dp"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="First Name"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="Last Name"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="UserName"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="Password"
/>
<LinearLayout
android:layout_width="200dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Password"
android:textColor="#android:color/black"
/>
</LinearLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="Email"
/>
</LinearLayout>
update
Do you want to achieve the result like following layout??
If so, Here is code.
android:layout_width="match_parent"
android:layout_height="match_parent"
>
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="First Name"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="Last Name"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="UserName"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="Password"
/>
<LinearLayout
android:layout_width="200dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Password"
android:textColor="#android:color/black"
/>
</LinearLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="Email"
/>
</LinearLayout>
Make sure to set the orientation of the parent layout to vertical. It is horizontal by default.
<LinearLayout
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- your inner layouts here -->
</LinearLayout>

Floating Action Button cannot be "found"

I have the following axml which includes a Floating Action Button which I use to provide instructions to the user. Originally I wasn't able to have the button float correctly at the bottom right of the screen because of the scrollview, but was fixed here: Floating action button over a scrollview stuck at top. Now that the button "floats" correctly, FindViewById can't find it! No idea whats going on, how can I fix this?
<android.support.design.widget.CoordinatorLayout
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:src="#drawable/Banner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView1" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center"
android:layout_marginTop="0sp"
android:background="#000000" />
<TextView
android:text="New Account"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView1"
android:textAlignment="center" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="Enter Username"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="150.5dp"
android:layout_height="wrap_content"
android:id="#+id/textView1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/aTextboxUsername" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="Enter Password"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="150.5dp"
android:layout_height="wrap_content"
android:id="#+id/textView1"/>
<EditText
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/aTextboxPassword"
android:autoLink="none" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="Confirm Password"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="150.5dp"
android:layout_height="wrap_content"
android:id="#+id/textView1"/>
<EditText
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/aTextboxPassword2"
android:autoLink="none" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="Enter Email Address"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="192.5dp"
android:layout_height="wrap_content"
android:id="#+id/textView1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtEmailAddress"
android:autoLink="none" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="Confirm Email Address"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="193.5dp"
android:layout_height="wrap_content"
android:id="#+id/textView1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtEmailAddress2"
android:autoLink="none" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="First Name" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/firstname"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="Middle Initial" />
<EditText
android:layout_width="50dp"
android:layout_height="wrap_content"
android:maxLength = "1"
android:id="#+id/mi"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="Last Name" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/lastname"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="130dp"
android:layout_height="35dp"
android:text="Suffix" />
<Spinner
android:layout_width="110dp"
android:layout_height="35dp"
android:id="#+id/spinner_suffix" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="Address" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/address"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="City" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/city"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="State" />
<Spinner
android:layout_width="110dp"
android:layout_height="35dp"
android:id="#+id/state" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="Zip Code" />
<EditText
android:layout_width="50dp"
android:layout_height="wrap_content"
android:maxLength = "5"
android:id="#+id/zip"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="Contact Phone" />
<MaskedEditText.MaskedEditText
app:Mask="(###) ###-####"
app:MaskFill="_"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/phone"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center"
android:layout_marginTop="0sp"
android:background="#000000" />
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="Select Company, Department, Section you are registering for." />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center"
android:layout_marginTop="0sp"
android:background="#000000" />
<TextView
android:text="Select Company"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:id="#+id/textView2" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:id="#+id/company_spinner" />
<TextView
android:text="Select Department"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:id="#+id/textView2" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:id="#+id/department_spinner" />
<TextView
android:text="Select Section"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:id="#+id/textView2" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:id="#+id/section_spinner" />
<Button
android:text="Submit"
android:layout_width="250px"
android:layout_gravity="center"
android:layout_height="34.5dp"
android:id="#+id/button_submit" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
app:layout_anchorGravity="bottom|end"
app:layout_anchor="#id/scrollView1"
android:src="#drawable/alert_box" />
</android.support.design.widget.CoordinatorLayout>
* EDIT *
The FindViewById Code:
FloatingActionButton myFab = FindViewById<FloatingActionButton>(Resource.Id.fab);`
Please delete the "bin" and "obj" folder in your project, after that, rebuild your project.

Xamarin.Android Spinner & TextView Align

I'm developing a Xamarin.Android application using VS2017. I want to create a form as in the image.
How to create it? I find it difficult to align TextView & Spinner.
My output:
This is my code.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/intialPadding"
android:background="#color/windowBackground">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="#dimen/textInputLayoutHeight">
<EditText
android:id="#+id/edt_RefuelingDate1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/colorSecondaryText"
android:layout_gravity="center"
android:hint="Date"
android:inputType="date" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="#dimen/textInputLayoutHeight"
android:layout_gravity="center">
<TextView
android:text="Vehicle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView2"
android:textSize="10dp"
android:paddingLeft="5dp" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/Widget.AppCompat.Spinner.Underlined"
android:id="#+id/spnrRefuelingVehicle"
android:layout_marginBottom="1.5dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="#dimen/textInputLayoutHeight"
android:layout_gravity="center">
<TextView
android:text="Fuel Type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView1"
android:textSize="10dp"
android:paddingLeft="5dp" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/Widget.AppCompat.Spinner.Underlined"
android:id="#+id/spnr_RefuelingFuelType1"
android:hint="Fuel Type" />
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/tilRefuelingFuelPrice1"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="#dimen/textInputLayoutHeight">
<EditText
android:hint="Fuel Price"
android:inputType="numberDecimal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/colorSecondaryText"
android:id="#+id/edt_RefuelingFuelPrice1" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/tilRefuelingOdometer1"
android:layout_width="match_parent"
android:layout_height="#dimen/textInputLayoutHeight">
<EditText
android:hint="Odometer"
android:inputType="numberDecimal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/colorSecondaryText"
android:id="#+id/edt_RefuelingOdometer1" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.design.widget.TextInputLayout
android:id="#+id/tilRefuelingAmount1"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="#dimen/textInputLayoutHeight">
<EditText
android:hint="Amount"
android:inputType="numberDecimal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/colorSecondaryText"
android:id="#+id/edt_RefuelingAmount1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/tilRefuelingQuantity1"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="#dimen/textInputLayoutHeight">
<EditText
android:hint="Quantity"
android:inputType="numberDecimal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/colorSecondaryText"
android:id="#+id/edt_RefuelingQuantity1" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView
android:text="Fuel Efficiency"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView1"
android:textSize="10dp"
android:paddingLeft="5dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tv_RefuelingAverage"
android:gravity="center_vertical"
android:text="Fuel Efficiency"
android:textAlignment="center"
android:paddingLeft="8dp" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
I was able to achieve it by using TableLayout.
Code:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="#dimen/intialPadding"
android:background="#color/windowBackground">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Vehicle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spnrRefuelingVehicle" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Fuel Type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:text="Fuel Price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/spnr_RefuelingFuelType1" />
<TextView
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/edt_RefuelingFuelPrice1" />
</TableRow>
</TableLayout>
Output

Android - Layout on phone differs from designer in size

Currently i'm developing a mobile application that shows some values (they will never change, so they are saved in a List). When i'm designing the page in the designer with device 4.7 WXGA i have much space to the bottom but on my real phone (Motorola Moto G3) there is no space.
Now i worry about what happens if i deploy the app on different phones (Samsung, etc). I always thought the advantage of creating a UI with something like AXML makes the app "responsive" in a meaning that it fits to the device which it is running on. But why is this not happening?
May someone give me a hint how to archieve this?
Edit:
Here is my AXML Code - for here i replaced the real text with Text
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1"
android:layout_marginTop="5dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2"
android:layout_margin="5dp"
android:gravity="center">
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/linearLayout6">
<ImageView
android:layout_width="32dp"
android:layout_height="40dp"
android:id="#+id/imgLeft"
android:src="#drawable/arrow_left"
android:layout_marginRight="50dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/linearLayout5"
android:gravity="center" />
<TextView
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/tbDin"
android:textSize="35dp"
android:layout_marginRight="15dp"
android:textColor="#android:color/black" />
<TextView
android:layout_width="60dp"
android:layout_height="match_parent"
android:id="#+id/tbDinWert"
android:textSize="35dp"
android:textColor="#android:color/black"
android:gravity="center"
android:text="XX" />
<ImageView
android:layout_width="32dp"
android:layout_height="40dp"
android:id="#+id/imgRight"
android:src="#drawable/arrow_right"
android:layout_marginLeft="50dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout3"
android:background="#android:color/transparent"
android:layout_marginTop="5dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/linearLayout4"
android:layout_margin="5dp"
android:paddingLeft="15dp">
<TextView
android:layout_width="90dp"
android:layout_height="match_parent"
android:id="#+id/tb1"
android:textSize="16dp"
android:layout_marginRight="142dp"
android:textColor="#android:color/black"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:gravity="center" />
<TextView
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/TextView4"
android:textSize="35dp"
android:background="#android:color/transparent"
android:inputType="none"
android:textColor="#android:color/black"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/linearLayout4"
android:layout_margin="5dp"
android:paddingLeft="15dp">
<TextView
android:layout_width="90dp"
android:layout_height="match_parent"
android:id="#+id/tb2"
android:textSize="16dp"
android:layout_marginRight="142dp"
android:textColor="#android:color/black"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:gravity="center" />
<TextView
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/TextView4"
android:textSize="35dp"
android:background="#android:color/transparent"
android:inputType="none"
android:textColor="#android:color/black"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/linearLayout4"
android:layout_margin="5dp"
android:paddingLeft="15dp">
<TextView
android:layout_width="90dp"
android:layout_height="match_parent"
android:id="#+id/tb3"
android:textSize="16dp"
android:layout_marginRight="142dp"
android:textColor="#android:color/black"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:gravity="center" />
<TextView
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/TextView4"
android:textSize="35dp"
android:background="#android:color/transparent"
android:inputType="none"
android:textColor="#android:color/black"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/linearLayout4"
android:layout_margin="5dp"
android:paddingLeft="15dp">
<TextView
android:layout_width="90dp"
android:layout_height="match_parent"
android:id="#+id/tb3"
android:textSize="16dp"
android:layout_marginRight="142dp"
android:textColor="#android:color/black"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:gravity="center" />
<TextView
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/TextView4"
android:textSize="35dp"
android:background="#android:color/transparent"
android:inputType="none"
android:textColor="#android:color/black"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/linearLayout4"
android:layout_margin="5dp"
android:paddingLeft="15dp">
<TextView
android:layout_width="90dp"
android:layout_height="match_parent"
android:id="#+id/tb4"
android:textSize="16dp"
android:layout_marginRight="142dp"
android:textColor="#android:color/black"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:gravity="center" />
<TextView
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/TextView4"
android:textSize="35dp"
android:background="#android:color/transparent"
android:inputType="none"
android:textColor="#android:color/black"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/linearLayout4"
android:layout_margin="5dp"
android:paddingLeft="15dp">
<TextView
android:layout_width="90dp"
android:layout_height="match_parent"
android:id="#+id/tb5"
android:textSize="16dp"
android:layout_marginRight="142dp"
android:textColor="#android:color/black"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:gravity="center" />
<TextView
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/TextView4"
android:textSize="35dp"
android:background="#android:color/transparent"
android:textColor="#android:color/black"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/linearLayout4"
android:layout_margin="5dp"
android:paddingLeft="15dp">
<TextView
android:layout_width="90dp"
android:layout_height="match_parent"
android:id="#+id/tb6"
android:textSize="10dp"
android:layout_marginRight="142dp"
android:textColor="#android:color/black"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:gravity="center" />
<TextView
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/TextView4"
android:textSize="35dp"
android:background="#android:color/transparent"
android:textColor="#android:color/black"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/linearLayout4"
android:layout_margin="5dp"
android:background="#android:color/transparent"
android:paddingLeft="15dp">
<TextView
android:layout_width="90dp"
android:layout_height="match_parent"
android:id="#+id/tb7"
android:textSize="10dp"
android:textColor="#android:color/black"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="142dp"
android:gravity="center" />
<TextView
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/TextView4"
android:textSize="35dp"
android:background="#android:color/transparent"
android:textColor="#android:color/black"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Ok, so first you cannot use same ids for views like linearLayout4. Second, correct practise is best practise so insted of creating so many layouts, create header and ListView and then populate it. Weather you have 3 item or 333 use ListView.
Next thing dont use android:layout_marginRight="142dp" like this. Margin and padding should be much smaller and for acheaving efect of streaching items use something like this:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout4"
android:layout_margin="5dp"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="16dp"
android:textColor="#android:color/black"
android:text="Value"
android:layout_weight="0.5"
android:gravity="center"/>
<TextView
android:text="Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="35dp"
android:textColor="#android:color/black"
android:layout_weight="0.5"
android:gravity="center"/>
</LinearLayout>
You can paste it to see the result.
Try to practise design in program that u are creating your app. If you are using AndroidStudio it has preview so you can check diferent size of screens.
And for any layout or view if you set android:layout_width="match_parent" android:layout_height="match_parent" it will always fit to the device.
Try creating layouts and view, with different background, while changing height and width so you can see what is happening.
You have to keep in mind that devices have different screen sizes and different densities. Don't set your pixel sizes in px, but in sp for fonts(scaleable pixels). For other things, use dp instead of px
You have to handle multiple screen sizes by creating layout-ldpi, mdpi, hdpi, xhdpi. So that any screen sizes is there, look and feel will be the same across all the devices,and also font should be in "sp" and other elements in "dp".
I think that you need a full-size None-Stretched Image in your aplication with this tutorial you can adapt a image in every device without problem
https://dzone.com/articles/using-full-size-none-stretched
or this other thing if you wanna adapt your app for the type of device or OS.
The static Device class includes several properties and methods that allow your code to deal with device differences at run time in a very simple and straightforward manner:
The Device.OS property returns a member of the TargetPlatform
enumeration: iOS, Android, WinPhone, or Other. The WinPhone member
refers to all the Windows and Windows Phone platforms.
The Device.Idiom property returns a member of the TargetIdiom
enumeration: Phone, Tablet, Desktop, or Unsupported.
You can use these two properties in if and else statements, or a switch and case block, to execute code specific to a particular platform.
https://developer.xamarin.com/guides/xamarin-forms/platform-features/device/
https://forums.xamarin.com/discussion/56817/how-to-use-platform-idiom-in-xaml
and in this book you can watch a excellent example the use of Device.OnPlatform page 58.
https://developer.xamarin.com/guides/xamarin-forms/creating-mobile-apps-xamarin-forms/
I hope with this you solve your problem. Regards.

How to marge the TableLayout I got 3rows,3col, marge row1&2 and row2&3

HELP
I using TableLayout & TableRow, in the picture below I trying to marge No.4 and No.6 together just like No.1 however I had no idea how to do it. For no.1 I was able to do cause I just using Layout-weight to divide the screen into 3row,3col .
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*">
<TableRow
android:layout_weight="2"
android:id="#+id/tableRow1">
<TextView
android:text="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="#android:color/holo_blue_dark" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_span="2"
android:stretchColumns="*"
android:id="#+id/tableLayout1">
<TableRow
android:layout_weight="1"
android:id="#+id/tableRow1"
android:background="#android:color/holo_red_dark">
<TextView
android:text="2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_span="2"
android:gravity="center" />
</TableRow>
<TableRow
android:layout_weight="1"
android:id="#+id/tableRow3">
<TextView
android:text="3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" />
<TextView
android:text="4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" />
</TableRow>
</TableLayout>
</TableRow>
<TableRow
android:layout_weight="1"
android:id="#+id/tableRow1">
<TextView
android:text="5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_span="2"
android:gravity="center"
android:background="#android:color/holo_green_dark" />
<TextView
android:text="6"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right" />
</TableRow>
</TableLayout>
below img is the result that i wants

Categories

Resources