I am making an android app to enter user information, for that I have two button and number picker, my button are customize and are not showing in either preview in android studio neither in emulator
Here is my code
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.tarun.dc2.Fragments.AddressFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical"
>
<!--Layout for Buttons-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
>
<com.app.tarun.dc2.CustomViews.SquareLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="25dp"
android:layout_weight="1">
<ImageButton
android:src="#drawable/ic_add"
android:id="#+id/medicineEditAddButton"
android:scaleType="fitCenter"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/green_button_style"/>
</com.app.tarun.dc2.CustomViews.SquareLayout>
<NumberPicker
android:layout_width="0dp"
android:id="#+id/medicineEditNumberPicker"
android:layout_height="wrap_content"
android:layout_weight="1">
</NumberPicker>
<com.app.tarun.dc2.CustomViews.SquareLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="25dp"
android:layout_weight="1">
<ImageButton
android:src="#drawable/ic_continue"
android:id="#+id/medicineEditContinueButton"
android:scaleType="fitCenter"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/yellow_button_style"/>
</com.app.tarun.dc2.CustomViews.SquareLayout>
</LinearLayout>
<!--Horizontal Linear Layout for EDITTEXT-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="First Name"
android:inputType="text"
android:layout_marginTop="25dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Last Name"
android:inputType="text"
android:layout_marginTop="25dp"/>
</LinearLayout>
<!--Horizontal Linear Layout for EDITTEXT end here(First name and last name-->
</LinearLayout></ScrollView>
Change your custom layout's width from 0dp to wrap content/match_parent depending on your need. I think that may solve your problem. I have your edited layout in below.
<com.app.tarun.dc2.CustomViews.SquareLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="25dp"
android:layout_weight="1">
<ImageButton
android:src="#drawable/ic_add"
android:id="#+id/medicineEditAddButton"
android:scaleType="fitCenter"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/green_button_style"/>
</com.app.tarun.dc2.CustomViews.SquareLayout>
<NumberPicker
android:layout_width="wrap_content"
android:id="#+id/medicineEditNumberPicker"
android:layout_height="wrap_content"
android:layout_weight="1">
</NumberPicker>
<com.app.tarun.dc2.CustomViews.SquareLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="25dp"
android:layout_weight="1">
<ImageButton
android:src="#drawable/ic_continue"
android:id="#+id/medicineEditContinueButton"
android:scaleType="fitCenter"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/yellow_button_style"/>
</com.app.tarun.dc2.CustomViews.SquareLayout>
Try including your scroll view in a layout. Here is how i have achieved it for a project of mine:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.com.atr.LoginActivity" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="#+id/txthello"></TextView>
<EditText
android:id="#+id/txtApp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txthello"
android:layout_marginTop="18dp"
android:hint="Enter Application Code"/>
<EditText
android:id="#+id/txtModuleId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtApp"
android:layout_marginTop="18dp"
android:hint="Enter Module Id"/>
<EditText
android:id="#+id/txtModuleCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtModuleId"
android:layout_marginTop="18dp"
android:hint="Enter Module Code"/>
<EditText
android:id="#+id/txtModuleType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtModuleCode"
android:layout_marginTop="18dp"
android:hint="Enter Module Type"/>
<EditText
android:id="#+id/txtSubModuleId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtModuleType"
android:layout_marginTop="18dp"
android:hint="Enter Sub Module Id"/>
<EditText
android:id="#+id/txtSubModuleCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtSubModuleId"
android:layout_marginTop="18dp"
android:hint="Enter Sub Module Code"/>
<EditText
android:id="#+id/txtUserId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtSubModuleCode"
android:layout_marginTop="18dp"
android:hint="Enter User Id"/>
<EditText
android:id="#+id/txtDateFrom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtUserId"
android:layout_marginTop="18dp"
android:hint="From Date (mmm-dd-yyyy)"/>
<EditText
android:id="#+id/txtDateTo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtDateFrom"
android:layout_marginTop="18dp"
android:hint="To Date (mmm-dd-yyyy)"/>
<Button
android:id="#+id/btnCallService"
android:layout_width="80dp"
android:layout_height="45dp"
android:layout_below="#+id/txtDateTo"
android:layout_toRightOf="#+id/txtDateTo"
android:layout_marginTop="18dp"
android:layout_alignParentLeft="true"
android:text="Send"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Just to give you a basic idea :)
Add a android:weightSum="[any int]" on your first LinearLayout
A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects.
So here you have to take LinearLayout or RelativeLayout and then you have to put different hierarchy of component.
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.tarun.dc2.Fragments.AddressFragment">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical"
>
<!--Layout for Buttons-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
>
<com.app.tarun.dc2.CustomViews.SquareLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="25dp"
android:layout_weight="1">
<ImageButton
android:src="#drawable/ic_add"
android:id="#+id/medicineEditAddButton"
android:scaleType="fitCenter"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/green_button_style"/>
</com.app.tarun.dc2.CustomViews.SquareLayout>
<NumberPicker
android:layout_width="0dp"
android:id="#+id/medicineEditNumberPicker"
android:layout_height="wrap_content"
android:layout_weight="1">
</NumberPicker>
<com.app.tarun.dc2.CustomViews.SquareLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="25dp"
android:layout_weight="1">
<ImageButton
android:src="#drawable/ic_continue"
android:id="#+id/medicineEditContinueButton"
android:scaleType="fitCenter"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/yellow_button_style"/>
</com.app.tarun.dc2.CustomViews.SquareLayout>
</LinearLayout>
<!--Horizontal Linear Layout for EDITTEXT-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="First Name"
android:inputType="text"
android:layout_marginTop="25dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Last Name"
android:inputType="text"
android:layout_marginTop="25dp"/>
</LinearLayout>
<!--Horizontal Linear Layout for EDITTEXT end here(First name and last name-->
</LinearLayout>
</LinearLayout></ScrollView>
Hope so this code is work for you.
And you can also visit this ScrollView
Related
enter image description here https://docs.google.com/document/d/1_ag-aMsJn408Yef_V0TbVC0GvRIbbuRRPd0uRgsNoM4/edit?usp=sharing
It's in red. I tried to solve it but I still can't resolve the error. :( I already found some similar questions around here but nothing helped me to solve this issue. I hope someone has an idea... ^.^
A valid XML file has only one root node.
Now It included LinearLayout and RelativeLayout.
You must put RelativeLayout and LinearLayout in a reasonable place.
You can do like this,but you need to change the location.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="sg.edu.tp.uxidcomt.LoginActivity">
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone"/>
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/action_sign_in"
android:textStyle="bold"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="#+id/layoutDots"
android:layout_width="match_parent"
android:layout_height="15dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="200dp"
android:gravity="center"
android:orientation="horizontal"></LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#id/layoutDots"
android:alpha=".5"
android:background="#android:color/white"/>
<Button
android:id="#+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#null"
android:next="NEXT"
android:textColor="#android:color/white"/>
<Button
android:id="#+id/btn_skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#null"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:text="SKIP"
android:textColor="#android:color/white"
tools:context=".LoginActivity"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
I have this interface:
Using the below fragment XML. Is it possible to align the widths of the TextViews so they are all the same width?
For example, ODOMETER appears to be the longest word in a textview. How can I adjust all the other TextView's widths to match ODOMETERS? That way they all line up and the interface would be neater.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.mycompany.myapp.Views.MasterDetails.VehicleFragment">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="false"
android:scrollbars="none">
<LinearLayout
android:id="#+id/scrollViewVehicle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- YEAR -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:paddingTop="10dp"
android:text="YEAR"
android:textColor="#color/COLOR_TXI_BLUE"
android:textStyle="bold"/>
<EditText
android:id="#+id/editYear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:imeOptions="actionDone"
android:inputType="number"
android:maxLength="4"
android:maxLines="1"/>
</LinearLayout>
<!-- MAKE -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:paddingTop="10dp"
android:text="MAKE"
android:textColor="#color/COLOR_TXI_BLUE"
android:textStyle="bold"/>
<AutoCompleteTextView
android:id="#+id/editMake"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLength="30"
android:maxLines="1"/>
</LinearLayout>
<!-- MODEL -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:paddingTop="10dp"
android:text="MODEL"
android:textColor="#color/COLOR_TXI_BLUE"
android:textStyle="bold"/>
<AutoCompleteTextView
android:id="#+id/editModel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLength="30"
android:maxLines="1"/>
</LinearLayout>
<!-- BODY -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:paddingTop="10dp"
android:text="BODY"
android:textColor="#color/COLOR_TXI_BLUE"
android:textStyle="bold"/>
<AutoCompleteTextView
android:id="#+id/editBody"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLength="30"
android:maxLines="1"/>
</LinearLayout>
<!-- COLOR -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:paddingTop="10dp"
android:text="COLOR"
android:textColor="#color/COLOR_TXI_BLUE"
android:textStyle="bold"/>
<AutoCompleteTextView
android:id="#+id/editColor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLength="30"
android:maxLines="1"/>
</LinearLayout>
<!-- TAG -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:paddingTop="10dp"
android:text="TAG"
android:textColor="#color/COLOR_TXI_BLUE"
android:textStyle="bold"/>
<EditText
android:id="#+id/editTag"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLength="30"
android:maxLines="1"/>
</LinearLayout>
<!-- STATE -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:paddingTop="10dp"
android:text="STATE"
android:textColor="#color/COLOR_TXI_BLUE"
android:textStyle="bold"/>
<AutoCompleteTextView
android:id="#+id/editState"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLength="30"
android:maxLines="1"/>
</LinearLayout>
<!-- Odometer -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:paddingTop="10dp"
android:text="ODOMETER"
android:textColor="#color/COLOR_TXI_BLUE"
android:textStyle="bold"/>
<EditText
android:id="#+id/editOdometer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLength="30"
android:maxLines="1"/>
</LinearLayout>
<!-- VIN -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:paddingTop="10dp"
android:text="VIN"
android:textColor="#color/COLOR_TXI_BLUE"
android:textStyle="bold"/>
<EditText
android:id="#+id/editVIN"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLength="17"
android:maxLines="1"/>
<Button
android:id="#+id/btnScanVIN"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/COLOR_TXI_BLUE"
android:text="SCAN"
android:textColor="#color/COLOR_TXI_WHITE"
android:textStyle="bold"/>
</LinearLayout>
<!-- Other -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:paddingTop="10dp"
android:text="OTHER"
android:textColor="#color/COLOR_TXI_BLUE"
android:textStyle="bold"/>
<EditText
android:id="#+id/editOther"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLength="30"
android:maxLines="1"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Of course it is possible. You're using a horizontal layout for every couple of label-text field. Do as follow:
add android:weightSum="z" to every LinearLayout
add android:layout_weight="0.y" to every Label
add android:layout_weight="0.x" to every Text Field
Note that 0.x + 0.y must equals to z. Obviously you need to set number values.
EDIT:
This code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.mycompany.myapp.Views.MasterDetails.VehicleFragment">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="false"
android:scrollbars="none">
<LinearLayout
android:id="#+id/scrollViewVehicle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- YEAR -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:paddingTop="10dp"
android:text="YEAR"
android:textColor="#color/COLOR_TXI_BLUE"
android:textStyle="bold"/>
<EditText
android:id="#+id/editYear"
android:layout_width="match_parent"
android:layout_weight="0.8"
android:layout_height="match_parent"
android:imeOptions="actionDone"
android:inputType="number"
android:maxLength="4"
android:maxLines="1"/>
</LinearLayout>
<!-- MAKE -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:paddingTop="10dp"
android:text="MAKE"
android:textColor="#color/COLOR_TXI_BLUE"
android:textStyle="bold"/>
<AutoCompleteTextView
android:id="#+id/editMake"
android:layout_width="match_parent"
android:layout_weight="0.8"
android:layout_height="match_parent"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLength="30"
android:maxLines="1"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Works great and I get this result
I want to implement the following layout:
I did it as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginRight="20dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL"
android:textSize="14sp"
android:layout_marginBottom="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:padding="10dp"
android:text="Text Box 1"
android:textSize="14sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL 2"
android:layout_marginBottom="5dp"
android:textSize="14sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="BLA-1"
android:background="#color/white"
android:textSize="14sp"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center|bottom"
android:text="and"
android:textSize="14sp"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="BLA-2"
android:background="#color/white"
android:textSize="14sp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Basically I used LinearLayouts and gravity.
It works but it seems kind of complex and I noticed that when I increase the margins left and right of the and text the texts BLA-1 and BLA-2 get cut off.
Is there a better way for this?
I think I can not use a relative layout as I would not be able to have the views take these sizes across the screen, right?
UPDATE:
Also with my approach any kind of padding in the TextViews cuts off the text
This looks the same as on screenshot (just customize colors)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFF"
android:hint="Text Box 1"
android:padding="4dp"
android:textColorHint="#757575" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL2" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFF"
android:hint="BLA-1"
android:padding="4dp"
android:textColorHint="#757575" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:text="and" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFF"
android:hint="BLA-2"
android:padding="4dp"
android:textColorHint="#757575" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I think LinearLayout is a good choise even though it is complex if you want to keep the weights.
You should change all your TextViews to wrap_content so they won't get cut off.
If you still want to avoid spaces you can wrap each TextView with a LinearLayout or FrameLayout like this:
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL2" />
</LinearLayout>
Here you can get it using Linear Layout. Have a look at below xml layout exactly what you are looking for.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="3"
tools:ignore="DisableBaselineAlignment">
<LinearLayout
android:id="#+id/llOne"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="LABEL"
android:textSize="14sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:hint="textbox1"
android:padding="10dp"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/llTwo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="LABEL"
android:textSize="14sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:hint="BLA1"
android:padding="10dp"
android:textSize="14sp" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="0.3"
android:text="and"
android:textSize="14sp" />
<LinearLayout
android:id="#+id/llThree"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_weight="0.6"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:hint="BLA2"
android:padding="10dp"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
I am trying to build this layout
But I am getting this: (The map button in the location would be ideal height and width but the textview doesn't match the height)
My location is a TextView and my destination is a EditText
I want the TextView and EditText to be the same width while the MAP buttons stay "square".
How can I get the textviews height to match and make a square map button?
Here is my layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragment_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mycompany.controller.DetailsFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/viewStatus"
android:layout_marginTop="5dp">
<LinearLayout
android:id="#+id/scrollViewDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- LOCATION -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="LOCATION"
android:textColor="#color/COLOR_BLUE"
android:textSize="24sp"/>
<LinearLayout
android:id="#+id/layoutLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/tvLocation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_weight=".8"
android:background="#color/COLOR_LIGHT_GREY"
android:text="123 MAIN ST., CHATTANOOGA TN 37404"
android:textSize="24sp"/>
<Button
android:id="#+id/btnMapLocation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight=".2"
android:background="#color/COLOR_BLUE"
android:text="MAP"
android:textColor="#color/COLOR_WHITE"/>
</LinearLayout>
<!-- DESTINATION -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="DESTINATION"
android:textColor="#color/COLOR_BLUE"
android:textSize="24sp"/>
<LinearLayout
android:id="#+id/layoutDestination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/editDestination"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight=".8"
android:ems="10"
android:inputType="textMultiLine"
android:text="407 Broad St., Anywhere ST 00000"/>
<Button
android:id="#+id/btnMapDestination"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight=".2"
android:background="#color/COLOR_BLUE"
android:text="MAP"
android:textColor="#color/COLOR_WHITE"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I did a slight modification in your code check it!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragment_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp">
<LinearLayout
android:id="#+id/scrollViewDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- LOCATION -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="LOCATION"
android:textSize="24sp"/>
<LinearLayout
android:id="#+id/layoutLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/searchText"
android:text="Search text here"
android:layout_weight="0.8"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#c8c8c8"
/>
<Button
android:id="#+id/searchButton"
android:text="MAP"
android:layout_weight="0.2"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
/>
</LinearLayout>
<!-- DESTINATION -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="DESTINATION"
android:textSize="24sp"/>
<LinearLayout
android:id="#+id/layoutLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/searchText"
android:text="Search text"
android:layout_weight="0.8"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<Button
android:id="#+id/searchButton"
android:text="MAP"
android:layout_weight="0.2"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Since you are using android:layout_weight, set android:layout_width="0dp"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragment_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mycompany.controller.DetailsFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/viewStatus"
android:layout_marginTop="5dp">
<LinearLayout
android:id="#+id/scrollViewDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- LOCATION -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="LOCATION"
android:textColor="#color/COLOR_BLUE"
android:textSize="24sp"/>
<LinearLayout
android:id="#+id/layoutLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/tvLocation"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_weight=".8"
android:background="#color/COLOR_LIGHT_GREY"
android:text="123 MAIN ST., CHATTANOOGA TN 37404"
android:textSize="24sp"/>
<Button
android:id="#+id/btnMapLocation"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:background="#color/COLOR_BLUE"
android:text="MAP"
android:textColor="#color/COLOR_WHITE"/>
</LinearLayout>
<!-- DESTINATION -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="DESTINATION"
android:textColor="#color/COLOR_BLUE"
android:textSize="24sp"/>
<LinearLayout
android:id="#+id/layoutDestination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/editDestination"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".8"
android:ems="10"
android:inputType="textMultiLine"
android:text="407 Broad St., Anywhere ST 00000"/>
<Button
android:id="#+id/btnMapDestination"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:background="#color/COLOR_BLUE"
android:text="MAP"
android:textColor="#color/COLOR_WHITE"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I'm trying to set my ImageView and LinearLayout to have half of the screen each. This works fine on tablets, but on smaller screens the image takes up the entire screen (thus, not actually working).
The way I see it is, I have set a layout_weight="1" on both the ImageView and LinearLayout and the layout_width="0dp" on both also. This SHOULD work, as I have researched a lot into this.
My Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/button_text_white">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/image"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:padding="20dp"
android:orientation="vertical"
android:gravity="bottom">
<TextView
android:id="#+id/text_view_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:gravity="center"
android:textSize="24dp"
android:textColor="#color/button_text_white"
android:visibility="invisible"/>
<TextView
android:id="#+id/text_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_in_username_text"
android:textColor="#color/color"/>
<EditText
android:id="#+id/edit_text_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:inputType="text"
android:textColor="#color/color"
android:hint="#string/sign_up_in_username_hint"/>
<TextView
android:id="#+id/text_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_in_email_text"
android:textColor="#color/color"/>
<EditText
android:id="#+id/edit_text_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:inputType="textEmailAddress"
android:textColor="#color/color"
android:hint="#string/sign_up_in_email_hint"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_in_password_text"
android:textColor="#color/color"/>
<EditText
android:id="#+id/edit_text_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:inputType="textPassword"
android:textColor="#color/color"
android:hint="#string/sign_up_in_password_hint"/>
<TextView
android:id="#+id/text_view_forgotten_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:gravity="right"
android:text="#string/forgotten_password_text"
android:textColor="#color/color"/>
<Button
android:id="#+id/button_sign_up_in"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="#color/color"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Thanks, appreciate any help!
I would say your problem is with your LinearLayout's height being set to match_parent inside of a ScrollView.
As you know, a ScrollView expands to fit its contents - now if you tell its contents to expand as big as its parent (match_parent), then you have a paradox.
Try setting the child of your ScrollView's height to wrap_content instead of match_parent.
There is no use for your ScrollView & it's parent RelativeLayout. Cut down your layout as below.
<LinearLayout>
<ImageView w="1"/>
<ScrollView w="1">
<LinearLayout>
....
</LinearLayout>
</ScrollView>
</LinearLayout>
.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/button_text_white">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/image"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:orientation="vertical"
android:gravity="bottom">
<TextView
android:id="#+id/text_view_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:gravity="center"
android:textSize="24dp"
android:textColor="#color/button_text_white"
android:visibility="invisible"/>
<TextView
android:id="#+id/text_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_in_username_text"
android:textColor="#color/color"/>
<EditText
android:id="#+id/edit_text_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:inputType="text"
android:textColor="#color/color"
android:hint="#string/sign_up_in_username_hint"/>
<TextView
android:id="#+id/text_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_in_email_text"
android:textColor="#color/color"/>
<EditText
android:id="#+id/edit_text_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:inputType="textEmailAddress"
android:textColor="#color/color"
android:hint="#string/sign_up_in_email_hint"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_in_password_text"
android:textColor="#color/color"/>
<EditText
android:id="#+id/edit_text_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:inputType="textPassword"
android:textColor="#color/color"
android:hint="#string/sign_up_in_password_hint"/>
<TextView
android:id="#+id/text_view_forgotten_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:gravity="right"
android:text="#string/forgotten_password_text"
android:textColor="#color/color"/>
<Button
android:id="#+id/button_sign_up_in"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="#color/color"/>
</LinearLayout>
</ScrollView>
</LinearLayout>